]> granicus.if.org Git - php/commitdiff
- Improve error messages (part 2)
authorMarcus Boerger <helly@php.net>
Sun, 21 May 2006 12:38:28 +0000 (12:38 +0000)
committerMarcus Boerger <helly@php.net>
Sun, 21 May 2006 12:38:28 +0000 (12:38 +0000)
Zend/zend_execute.c
tests/lang/bug24658.phpt

index fea2ebe09f3f0560bfbf39511e4bcf093950b9ca..e98a19907543fead3a6b09dc4ccd56c895d98c50 100644 (file)
@@ -477,8 +477,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 *fsep;
+       char *fsep, *error_msg;
        zstr fclass, fname;
+       zend_class_entry *ce;
 
        if (!zf->common.arg_info
                || arg_num>zf->common.num_args) {
@@ -511,9 +512,8 @@ static inline int zend_verify_arg_type(zend_function *zf, zend_uint arg_num, zva
                                }
                                break;
                        case IS_OBJECT: {
-                                       zend_class_entry *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);
+                                       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)) {
-                                               char *error_msg;
                                                if (ce->ce_flags & ZEND_ACC_INTERFACE) {
                                                        error_msg = "implement interface";
                                                } else {
@@ -528,13 +528,20 @@ static inline int zend_verify_arg_type(zend_function *zf, zend_uint arg_num, zva
                                        }
                                }
                                break;
-                       default:
+                       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 be an object of class %v, %s given, called in %s on line %d and defined", arg_num, fclass, fsep, fname, cur_arg_info->class_name, zend_zval_type_name(arg), ptr->op_array->filename, ptr->opline->lineno);
+                                       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 be an object of class %v, %s given", arg_num, fclass, fsep, fname, cur_arg_info->class_name, zend_zval_type_name(arg));
+                                       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;
+                       }
                }
        } else if (cur_arg_info->array_type_hint) {
                if (!arg) {
index 5a5782a3d6e6b377b3817bea7837b303c96735c9..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, integer given 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