]> granicus.if.org Git - php/commitdiff
- Sync error messages and simplify error message generation code
authorMarcus Boerger <helly@php.net>
Fri, 26 May 2006 00:26:45 +0000 (00:26 +0000)
committerMarcus Boerger <helly@php.net>
Fri, 26 May 2006 00:26:45 +0000 (00:26 +0000)
Zend/tests/bug33996.phpt
Zend/zend_execute.c
tests/classes/interfaces_003.phpt

index 099b6176f43e4020392453db50dd156c8a8b9f88..e722eceafb3e97f46c17f8bc6328b728ef0800d2 100755 (executable)
@@ -26,4 +26,4 @@ FooTest(new Foo());
 --EXPECTF--
 Warning: Missing argument 1 for NormalTest(), called in %sbug33996.php on line %d and defined in %sbug33996.php on line %d
 Hi!
-Catchable fatal error: Argument 1 passed to FooTest() must be an object of class Foo, none given, called in %sbug33996.php on line %d and defined in %sbug33996.php on line %d
+Catchable fatal error: Argument 1 passed to FooTest() must be an instance of Foo, none given, called in %sbug33996.php on line %d and defined in %sbug33996.php on line %d
index e98a19907543fead3a6b09dc4ccd56c895d98c50..e2bd803857ff9d4b430b692e39875b06062be70a 100644 (file)
@@ -473,12 +473,44 @@ static inline void make_real_object(zval **object_ptr TSRMLS_DC)
        }
 }
 
+static inline char * zend_verify_arg_class_kind(zend_arg_info *cur_arg_info, zend_class_entry **pce TSRMLS_DC)
+{
+       *pce = zend_u_fetch_class(UG(unicode) ? IS_UNICODE : IS_STRING, cur_arg_info->class_name, cur_arg_info->class_name_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
+
+       if ((*pce)->ce_flags & ZEND_ACC_INTERFACE) {
+               return "implement interface ";
+       } else {
+               return "be an instance of ";
+       }
+}
+
+static inline int zend_verify_arg_error(zend_function *zf, zend_uint arg_num, zend_arg_info *cur_arg_info, char *need_msg, zstr need_kind, char *given_msg, zstr given_kind TSRMLS_DC)
+{
+       zend_execute_data *ptr = EG(current_execute_data)->prev_execute_data;
+       zstr fname = zf->common.function_name;
+       char *fsep;
+       zstr fclass;
+
+       if (zf->common.scope) {
+               fsep =  "::";
+               fclass = zf->common.scope->name;
+       } else {
+               fsep =  "";
+               fclass = EMPTY_ZSTR;
+       }
+
+       if (ptr && ptr->op_array) {
+               zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %v%s%v() must %s%v, %s%v given, called in %s on line %d and defined", arg_num, fclass, fsep, fname, need_msg, need_kind, given_msg, given_kind, ptr->op_array->filename, ptr->opline->lineno);
+       } else {
+               zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %v%s%v() must %s%v, %s%v given", arg_num, fclass, fsep, fname, need_msg, need_kind, given_msg, given_kind);
+       }
+       return 0;
+}
+
 static inline int zend_verify_arg_type(zend_function *zf, zend_uint arg_num, zval *arg TSRMLS_DC)
 {
        zend_arg_info *cur_arg_info;
-       zend_execute_data *ptr = EG(current_execute_data)->prev_execute_data;
-       char *fsep, *error_msg;
-       zstr fclass, fname;
+       char *need_msg;
        zend_class_entry *ce;
 
        if (!zf->common.arg_info
@@ -487,91 +519,27 @@ static inline int zend_verify_arg_type(zend_function *zf, zend_uint arg_num, zva
        }
 
        cur_arg_info = &zf->common.arg_info[arg_num-1];
-       fname = zf->common.function_name;
-       fsep = zf->common.scope ? "::" : "";
-       fclass = zf->common.scope ? zf->common.scope->name : EMPTY_ZSTR;
 
        if (cur_arg_info->class_name.v) {
                if (!arg) {
-                       if (ptr && ptr->op_array) {
-                               zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %v%s%v() must be an object of class %v, 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 %v%s%v() must be an object of class %v, none given", arg_num, fclass, fsep, fname, cur_arg_info->class_name);
-                       }
-                       return 0;
+                       need_msg = zend_verify_arg_class_kind(cur_arg_info, &ce TSRMLS_CC);
+                       return zend_verify_arg_error(zf, arg_num, cur_arg_info, need_msg, ce->name, "none", EMPTY_ZSTR TSRMLS_CC);
                }
-               switch (Z_TYPE_P(arg)) {
-                       case IS_NULL:
-                               if (!cur_arg_info->allow_null) {
-                                       if (ptr && ptr->op_array) {
-                                               zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %v%s%v() must be an object of class %v, 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 %v%s%v() must be an object of class %v, null given", arg_num, fclass, fsep, fname, cur_arg_info->class_name);
-                                       }
-                                       return 0;
-                               }
-                               break;
-                       case IS_OBJECT: {
-                                       ce = zend_u_fetch_class(UG(unicode) ? IS_UNICODE : IS_STRING, 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)) {
-                                               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 %v%s%v() must %s %v, instance of %v 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 %v%s%v() must %s %v, instance of %v given", arg_num, fclass, fsep, fname, error_msg, ce->name, Z_OBJCE_P(arg)->name);
-                                               }
-                                               return 0;
-                                       }
-                               }
-                               break;
-                       default: {
-                               ce = zend_u_fetch_class(UG(unicode) ? IS_UNICODE : IS_STRING, 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 %v%s%v() must %s %v, %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 %v%s%v() must %s %v, %s given", arg_num, fclass, fsep, fname, error_msg, ce->name, zend_zval_type_name(arg));
-                               }
-                               return 0;
+               if (Z_TYPE_P(arg) == IS_OBJECT) {
+                       need_msg = zend_verify_arg_class_kind(cur_arg_info, &ce TSRMLS_CC);
+                       if (!instanceof_function(Z_OBJCE_P(arg), ce TSRMLS_CC)) {
+                               return zend_verify_arg_error(zf, arg_num, cur_arg_info, need_msg, ce->name, "instance of ", Z_OBJCE_P(arg)->name TSRMLS_CC);
                        }
+               } else if (Z_TYPE_P(arg) != IS_NULL || !cur_arg_info->allow_null) {
+                       need_msg = zend_verify_arg_class_kind(cur_arg_info, &ce TSRMLS_CC);
+                       return zend_verify_arg_error(zf, arg_num, cur_arg_info, need_msg, ce->name, zend_zval_type_name(arg), EMPTY_ZSTR TSRMLS_CC);
                }
        } else if (cur_arg_info->array_type_hint) {
                if (!arg) {
-                       if (ptr && ptr->op_array) {
-                               zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %v%s%v() 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 %v%s%v() must be an array, none given", arg_num, fclass, fsep, fname);
-                       }
-                       return 0;
+                       return zend_verify_arg_error(zf, arg_num, cur_arg_info, "be an array", EMPTY_ZSTR, "none", EMPTY_ZSTR TSRMLS_CC);
                }
-               switch (Z_TYPE_P(arg)) {
-                       case IS_NULL:
-                               if (!cur_arg_info->allow_null) {
-                                       if (ptr && ptr->op_array) {
-                                               zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %v%s%v() 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 %v%s%v() must be an array, null given", arg_num, fclass, fsep, fname);
-                                       }
-                                       return 0;
-                               }
-                               break;
-                       case IS_ARRAY:
-                               break;
-                       default:
-                               if (ptr && ptr->op_array) {
-                                       zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %v%s%v() 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 %v%s%v() must be an array, %s given", arg_num, fclass, fsep, fname, zend_zval_type_name(arg));
-                               }
-                               return 0;
+               if (Z_TYPE_P(arg) != IS_ARRAY && (Z_TYPE_P(arg) != IS_NULL || !cur_arg_info->allow_null)) {
+                       return zend_verify_arg_error(zf, arg_num, cur_arg_info, "be an array", EMPTY_ZSTR, zend_zval_type_name(arg), EMPTY_ZSTR TSRMLS_CC);
                }
        }
        return 1;
index 7bdca933e7c68651fb55bbd5e4e486579f32d808..f9ab92bb151a1d05a1b6a5db6cc06571a620a1a0 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, none given, called in %sinterfaces_003.php on line %d
+Catchable fatal error: Argument 1 passed to MyTestClass::__construct() must be an instance of MyObject, none given, called in %sinterfaces_003.php on line %d