]> granicus.if.org Git - php/commitdiff
- MFH improve error messages
authorMarcus Boerger <helly@php.net>
Sun, 21 May 2006 18:10:31 +0000 (18:10 +0000)
committerMarcus Boerger <helly@php.net>
Sun, 21 May 2006 18:10:31 +0000 (18:10 +0000)
Zend/tests/array_type_hint_001.phpt
Zend/tests/bug33996.phpt
Zend/zend_execute.c
tests/classes/interfaces_003.phpt
tests/classes/type_hinting_001.phpt
tests/classes/type_hinting_003.phpt
tests/lang/bug24658.phpt
tests/lang/type_hints_001.phpt

index 4c4f048df76496cd8af6bc164591483fde825617..533319b6eab5b0aef13b368d1b38073024e6374b 100755 (executable)
@@ -12,4 +12,4 @@ foo(123);
 --EXPECTF--
 3
 
-Catchable fatal error: Argument 1 passed to foo() must be an array, called in %sarray_type_hint_001.php on line 7 and defined in %sarray_type_hint_001.php on line 2
+Catchable fatal error: Argument 1 passed to foo() must be an array, integer given, called in %sarray_type_hint_001.php on line 7 and defined in %sarray_type_hint_001.php on line 2
index 27fa60aaf9405a923bf6ef6ce20f2e95c7ebfd83..c4033cd7b94c8abd0313fa29d1487c40f72fdeee 100755 (executable)
@@ -26,5 +26,5 @@ FooTest(new Foo());
 --EXPECTF--
 Warning: Missing argument 1 for NormalTest(), called in %sbug33996.php on line 17 and defined in %sbug33996.php on line 12
 Hi!
-Catchable fatal error: Argument 1 passed to FooTest() must be an object of class Foo, called in %sbug33996.php on line 18 and defined in %sbug33996.php on line 7
+Catchable fatal error: Argument 1 passed to FooTest() must be an object of class Foo, none given, called in %sbug33996.php on line 18 and defined in %sbug33996.php on line 7
 
index 1b32b3b99baf0fdd11f0022c03359378eacad7d3..29ee695301559b00e0841317ef584021d3e63b4a 100644 (file)
@@ -454,7 +454,9 @@ static inline int zend_verify_arg_type(zend_function *zf, zend_uint arg_num, zva
 {
        zend_arg_info *cur_arg_info;
        zend_execute_data *ptr = EG(current_execute_data)->prev_execute_data;
-       char *fclass, *fsep, *fname;
+       char *fsep, *error_msg;
+       char *fclass, *fname;
+       zend_class_entry *ce;
 
        if (!zf->common.arg_info
                || arg_num>zf->common.num_args) {
@@ -469,9 +471,9 @@ static inline int zend_verify_arg_type(zend_function *zf, zend_uint arg_num, zva
        if (cur_arg_info->class_name) {
                if (!arg) {
                        if (ptr && ptr->op_array) {
-                               zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must be an object of class %s, called in %s on line %d and defined", arg_num, fclass, fsep, fname, cur_arg_info->class_name, ptr->op_array->filename, ptr->opline->lineno);
+                               zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must be an object of class %s, none given, called in %s on line %d and defined", arg_num, fclass, fsep, fname, cur_arg_info->class_name, ptr->op_array->filename, ptr->opline->lineno);
                        } else {
-                               zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must be an object of class %s", arg_num, fclass, fsep, fname, cur_arg_info->class_name);
+                               zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must be an object of class %s, none given", arg_num, fclass, fsep, fname, cur_arg_info->class_name);
                        }
                        return 0;
                }
@@ -479,45 +481,51 @@ static inline int zend_verify_arg_type(zend_function *zf, zend_uint arg_num, zva
                        case IS_NULL:
                                if (!cur_arg_info->allow_null) {
                                        if (ptr && ptr->op_array) {
-                                               zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must not be null, called in %s on line %d and defined", arg_num, fclass, fsep, fname, ptr->op_array->filename, ptr->opline->lineno);
+                                               zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must be an object of class %s, null given, called in %s on line %d and defined", arg_num, fclass, fsep, fname, cur_arg_info->class_name, ptr->op_array->filename, ptr->opline->lineno);
                                        } else {
-                                               zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must not be null", arg_num, fclass, fsep, fname);
+                                               zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must be an object of class %s, null given", arg_num, fclass, fsep, fname, cur_arg_info->class_name);
                                        }
                                        return 0;
                                }
                                break;
                        case IS_OBJECT: {
-                                       zend_class_entry *ce = zend_fetch_class(cur_arg_info->class_name, cur_arg_info->class_name_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
+                                       ce = zend_fetch_class(cur_arg_info->class_name, cur_arg_info->class_name_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
                                        if (!instanceof_function(Z_OBJCE_P(arg), ce TSRMLS_CC)) {
-                                               char *error_msg;
                                                if (ce->ce_flags & ZEND_ACC_INTERFACE) {
                                                        error_msg = "implement interface";
                                                } else {
                                                        error_msg = "be an instance of";
                                                }
                                                if (ptr && ptr->op_array) {
-                                                       zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must %s %s, called in %s on line %d and defined", arg_num, fclass, fsep, fname, error_msg, ce->name, ptr->op_array->filename, ptr->opline->lineno);
+                                                       zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must %s %s, instance of %s given, called in %s on line %d and defined", arg_num, fclass, fsep, fname, error_msg, ce->name, Z_OBJCE_P(arg)->name, ptr->op_array->filename, ptr->opline->lineno);
                                                } else {
-                                                       zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must %s %s", arg_num, fclass, fsep, fname, error_msg, ce->name);
+                                                       zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must %s %s, instance of %s given", arg_num, fclass, fsep, fname, error_msg, ce->name, Z_OBJCE_P(arg)->name);
                                                }
                                                return 0;
                                        }
                                }
                                break;
-                       default:
+                       default: {
+                               ce = zend_fetch_class(cur_arg_info->class_name, cur_arg_info->class_name_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
+                               if (ce->ce_flags & ZEND_ACC_INTERFACE) {
+                                       error_msg = "implement interface";
+                               } else {
+                                       error_msg = "be an instance of";
+                               }
                                if (ptr && ptr->op_array) {
-                                       zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must be an object of class %s, called in %s on line %d and defined", arg_num, fclass, fsep, fname, cur_arg_info->class_name, ptr->op_array->filename, ptr->opline->lineno);
+                                       zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must %s %s, %s given, called in %s on line %d and defined", arg_num, fclass, fsep, fname, error_msg, ce->name, zend_zval_type_name(arg), ptr->op_array->filename, ptr->opline->lineno);
                                } else {
-                                       zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must be an object of class %s", arg_num, fclass, fsep, fname, cur_arg_info->class_name);
+                                       zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must %s %s, %s given", arg_num, fclass, fsep, fname, error_msg, ce->name, zend_zval_type_name(arg));
                                }
                                return 0;
+                       }
                }
        } else if (cur_arg_info->array_type_hint) {
                if (!arg) {
                        if (ptr && ptr->op_array) {
-                               zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must be an array, called in %s on line %d and defined", arg_num, fclass, fsep, fname, ptr->op_array->filename, ptr->opline->lineno);
+                               zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must be an array, none given, called in %s on line %d and defined", arg_num, fclass, fsep, fname, ptr->op_array->filename, ptr->opline->lineno);
                        } else {
-                               zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must be an array", arg_num, fclass, fsep, fname);
+                               zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must be an array, none given", arg_num, fclass, fsep, fname);
                        }
                        return 0;
                }
@@ -525,9 +533,9 @@ static inline int zend_verify_arg_type(zend_function *zf, zend_uint arg_num, zva
                        case IS_NULL:
                                if (!cur_arg_info->allow_null) {
                                        if (ptr && ptr->op_array) {
-                                               zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must not be null, called in %s on line %d and defined", arg_num, fclass, fsep, fname, ptr->op_array->filename, ptr->opline->lineno);
+                                               zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must be an array, null given, called in %s on line %d and defined", arg_num, fclass, fsep, fname, ptr->op_array->filename, ptr->opline->lineno);
                                        } else {
-                                               zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must not be null", arg_num, fclass, fsep, fname);
+                                               zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must be an array, null given", arg_num, fclass, fsep, fname);
                                        }
                                        return 0;
                                }
@@ -536,9 +544,9 @@ static inline int zend_verify_arg_type(zend_function *zf, zend_uint arg_num, zva
                                break;
                        default:
                                if (ptr && ptr->op_array) {
-                                       zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must be an array, called in %s on line %d and defined", arg_num, fclass, fsep, fname, ptr->op_array->filename, ptr->opline->lineno);
+                                       zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must be an array, %s given, called in %s on line %d and defined", arg_num, fclass, fsep, fname, zend_zval_type_name(arg), ptr->op_array->filename, ptr->opline->lineno);
                                } else {
-                                       zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must be an array", arg_num, fclass, fsep, fname);
+                                       zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must be an array, %s given", arg_num, fclass, fsep, fname, zend_zval_type_name(arg));
                                }
                                return 0;
                }
index 2c4c7e7c94fe7bce33f8aabdf00a0fe4d5ab4ba7..7bdca933e7c68651fb55bbd5e4e486579f32d808 100755 (executable)
@@ -23,4 +23,4 @@ $obj = new MyTestClass;
 ===DONE===
 --EXPECTF--
 
-Catchable fatal error: Argument 1 passed to MyTestClass::__construct() must be an object of class MyObject, called in %sinterfaces_003.php on line %d
+Catchable fatal error: Argument 1 passed to MyTestClass::__construct() must be an object of class MyObject, none given, called in %sinterfaces_003.php on line %d
index 17cf57e3441b53f31c3a256c96309fdc0f54acbf..f55dd53bf4c9351722b7f797e571e397f4ec48c9 100644 (file)
@@ -35,4 +35,4 @@ $a->b($b);
 ?>
 --EXPECTF--
 
-Catchable fatal error: Argument 1 passed to FooBar::a() must implement interface Foo, called in %s on line 27 and defined in %s on line 12
+Catchable fatal error: Argument 1 passed to FooBar::a() must implement interface Foo, instance of Blort given, called in %s on line 27 and defined in %s on line 12
index ea01fc2dcb118c386599d3f7855f532edf0164dc..431d66eabc2631212a97497dbc84bc9123923729 100755 (executable)
@@ -57,4 +57,4 @@ array(1) {
   int(25)
 }
 
-Catchable fatal error: Argument 1 passed to Test::f1() must be an array, called in %stype_hinting_003.php on line %d and defined in %stype_hinting_003.php on line %d
+Catchable fatal error: Argument 1 passed to Test::f1() must be an array, integer given, called in %stype_hinting_003.php on line %d and defined in %stype_hinting_003.php on line %d
index 5f3b324b61ee9a4c506260a5c6fcd5c575547790..944fe44ce8f7a0308425a5845dd52fd77e26dc3d 100644 (file)
@@ -53,4 +53,4 @@ int(2)
 object(foo)#%d (0) {
 }
 
-Catchable fatal error: Argument 1 passed to typehint() must be an object of class foo in %s on line %d
+Catchable fatal error: Argument 1 passed to typehint() must be an instance of foo, integer given in %s on line %d
index dc14706a362b9add036001529a3ba48c256f2a54..57808d474f6a88897c1baac64f783c7672d004af 100644 (file)
@@ -23,4 +23,4 @@ type_hint_foo($bar);
 ?>
 --EXPECTF--
 
-Catchable fatal error: Argument 1 passed to type_hint_foo() must be an instance of Foo, called in %s on line 16 and defined in %s on line 9
+Catchable fatal error: Argument 1 passed to type_hint_foo() must be an instance of Foo, instance of Bar given, called in %s on line 16 and defined in %s on line 9