]> granicus.if.org Git - php/commitdiff
fix error messages when converting objects to other types
authorAntony Dovgal <tony2001@php.net>
Thu, 25 May 2006 10:01:06 +0000 (10:01 +0000)
committerAntony Dovgal <tony2001@php.net>
Thu, 25 May 2006 10:01:06 +0000 (10:01 +0000)
add new function
MFB will follow soon

Zend/zend_API.c
Zend/zend_API.h
Zend/zend_operators.c

index 2cd889932c3b402cc146dd6b7eea260fb8bb6194..3c7f213c7185e0400714fd8cad60770bd0010764 100644 (file)
@@ -195,38 +195,35 @@ 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:
                        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";
                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 0a894e20c3f1e5ef2a76955db84f328dcd231563..2669ea216c1aa258ad72b165a019474c4bd7ad70 100644 (file)
@@ -258,6 +258,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, char **class_name, zend_uint *class_name_len TSRMLS_DC);
+ZEND_API char *zend_get_type_by_const(int type);
 
 #define getThis() (this_ptr)
 
index cb207b18096ca08e07f7c1de21f3b2cca5117801..65a224840a955a2d9bee2728751e6b81dca0ca21 100644 (file)
@@ -271,7 +271,8 @@ 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 %s could not be converted to " # ctype, Z_OBJCE_P(op)->name);  \
+                       "Object of class %s 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;                                                                                                                   \