]> granicus.if.org Git - php/commitdiff
MFB: fix error messages when converting objects to other types
authorAntony Dovgal <tony2001@php.net>
Thu, 25 May 2006 10:34:01 +0000 (10:34 +0000)
committerAntony Dovgal <tony2001@php.net>
Thu, 25 May 2006 10:34:01 +0000 (10:34 +0000)
Zend/zend_API.c
Zend/zend_API.h
Zend/zend_operators.c

index 9ff45fc1236f546123bf4bb3323fb32f9721efe4..2ab16741a412162d619574053283f27383e07547 100644 (file)
@@ -194,19 +194,15 @@ ZEND_API void zend_wrong_param_count(TSRMLS_D)
 
 
 /* Argument parsing API -- andrei */
-
-ZEND_API char *zend_zval_type_name(zval *arg)
+ZEND_API char *zend_get_type_by_const(int type)
 {
-       switch (Z_TYPE_P(arg)) {
-               case IS_NULL:
-                       return "null";
-
+       switch(type) {
+               case IS_BOOL:
+                       return "boolean";
                case IS_LONG:
                        return "integer";
-
                case IS_DOUBLE:
                        return "double";
-
                case IS_STRING:
                {
                        TSRMLS_FETCH();
@@ -217,26 +213,26 @@ ZEND_API char *zend_zval_type_name(zval *arg)
                                return "string";
                        }
                }
-               case IS_ARRAY:
-                       return "array";
-
                case IS_OBJECT:
                        return "object";
-
-               case IS_BOOL:
-                       return "boolean";
-
                case IS_RESOURCE:
                        return "resource";
-
+               case IS_NULL:
+                       return "null";
+               case IS_ARRAY:
+                       return "array";
                case IS_UNICODE:
                        return "Unicode string";
-
                default:
                        return "unknown";
        }
 }
 
+ZEND_API char *zend_zval_type_name(zval *arg)
+{
+       return zend_get_type_by_const(Z_TYPE_P(arg));
+}
+
 ZEND_API zend_class_entry *zend_get_class_entry(zval *zobject TSRMLS_DC)
 {
        if (Z_OBJ_HT_P(zobject)->get_class_entry) {
index 5ab491e2499e78552a691097c9daf8b472f3b836..1ef01368a3461a4ec76611c543e679678319667d 100644 (file)
@@ -289,6 +289,7 @@ ZEND_API zval *zend_read_static_property(zend_class_entry *scope, char *name, in
 ZEND_API zend_class_entry *zend_get_class_entry(zval *zobject TSRMLS_DC);
 ZEND_API int zend_get_object_classname(zval *object, zstr *class_name, zend_uint *class_name_len TSRMLS_DC);
 ZEND_API zend_uchar zend_get_unified_string_type(int num_args TSRMLS_DC, ...);
+ZEND_API char *zend_get_type_by_const(int type);
 
 #define getThis() (this_ptr)
 
index c60458789b8f6e88359662a89af11eb53065f7b8..028e99c326cdfd7929d638b8d47a3f309a2cfba6 100644 (file)
@@ -318,10 +318,11 @@ ZEND_API void convert_scalar_to_number(zval *op TSRMLS_DC)
                zval dst;                                                                                                                                                       \
                if (Z_OBJ_HT_P(op)->cast_object(op, &dst, ctype TSRMLS_CC) == FAILURE) {                        \
                        zend_error(E_RECOVERABLE_ERROR,                                                                                                 \
-                       "Object of class %v could not be converted to " # ctype, Z_OBJCE_P(op)->name);  \
+                       "Object of class %v could not be converted to %s", Z_OBJCE_P(op)->name,                 \
+                       zend_get_type_by_const(ctype));                                                                                                 \
                } else {                                                                                                                                                        \
                        zval_dtor(op);                                                                                                                                  \
-                       Z_TYPE_P(op) = ctype;                                                                                                                           \
+                       Z_TYPE_P(op) = ctype;                                                                                                                   \
                        op->value = dst.value;                                                                                                                  \
                }                                                                                                                                                                       \
        } else {                                                                                                                                                                \