helly           Fri May 26 00:26:45 2006 UTC

  Modified files:              
    /ZendEngine2        zend_execute.c 
    /ZendEngine2/tests  bug33996.phpt 
    /php-src/tests/classes      interfaces_003.phpt 
  Log:
  - Sync error messages and simplify error message generation code
  
  
http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_execute.c?r1=1.744&r2=1.745&diff_format=u
Index: ZendEngine2/zend_execute.c
diff -u ZendEngine2/zend_execute.c:1.744 ZendEngine2/zend_execute.c:1.745
--- ZendEngine2/zend_execute.c:1.744    Sun May 21 12:38:28 2006
+++ ZendEngine2/zend_execute.c  Fri May 26 00:26:44 2006
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_execute.c,v 1.744 2006/05/21 12:38:28 helly Exp $ */
+/* $Id: zend_execute.c,v 1.745 2006/05/26 00:26:44 helly Exp $ */
 
 #define ZEND_INTENSIVE_DEBUGGING 0
 
@@ -473,12 +473,44 @@
        }
 }
 
+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 @@
        }
 
        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;
http://cvs.php.net/viewcvs.cgi/ZendEngine2/tests/bug33996.phpt?r1=1.4&r2=1.5&diff_format=u
Index: ZendEngine2/tests/bug33996.phpt
diff -u ZendEngine2/tests/bug33996.phpt:1.4 ZendEngine2/tests/bug33996.phpt:1.5
--- ZendEngine2/tests/bug33996.phpt:1.4 Sun May 21 11:23:35 2006
+++ ZendEngine2/tests/bug33996.phpt     Fri May 26 00:26:45 2006
@@ -26,4 +26,4 @@
 --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
http://cvs.php.net/viewcvs.cgi/php-src/tests/classes/interfaces_003.phpt?r1=1.3&r2=1.4&diff_format=u
Index: php-src/tests/classes/interfaces_003.phpt
diff -u php-src/tests/classes/interfaces_003.phpt:1.3 
php-src/tests/classes/interfaces_003.phpt:1.4
--- php-src/tests/classes/interfaces_003.phpt:1.3       Sun May 21 11:23:35 2006
+++ php-src/tests/classes/interfaces_003.phpt   Fri May 26 00:26:45 2006
@@ -23,4 +23,4 @@
 ===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

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to