tony2001                Mon Oct  2 11:05:02 2006 UTC

  Added files:                 
    /ZendEngine2/tests  bug39003.phpt 

  Modified files:              
    /ZendEngine2        zend_execute.c 
    /php-src/tests/classes      type_hinting_002.phpt 
  Log:
  fix #39003 (__autoload() is called for type hinting)
  
  
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_execute.c?r1=1.751&r2=1.752&diff_format=u
Index: ZendEngine2/zend_execute.c
diff -u ZendEngine2/zend_execute.c:1.751 ZendEngine2/zend_execute.c:1.752
--- ZendEngine2/zend_execute.c:1.751    Wed Aug 30 09:58:10 2006
+++ ZendEngine2/zend_execute.c  Mon Oct  2 11:05:02 2006
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_execute.c,v 1.751 2006/08/30 09:58:10 tony2001 Exp $ */
+/* $Id: zend_execute.c,v 1.752 2006/10/02 11:05:02 tony2001 Exp $ */
 
 #define ZEND_INTENSIVE_DEBUGGING 0
 
@@ -472,11 +472,12 @@
        }
 }
 
-static inline char * zend_verify_arg_class_kind(zend_arg_info *cur_arg_info, 
zend_class_entry **pce TSRMLS_DC)
+static inline char * zend_verify_arg_class_kind(zend_arg_info *cur_arg_info, 
zstr *class_name, 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);
+       *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 
| ZEND_FETCH_CLASS_NO_AUTOLOAD) TSRMLS_CC);
 
-       if ((*pce)->ce_flags & ZEND_ACC_INTERFACE) {
+       *class_name = (*pce) ? (*pce)->name: cur_arg_info->class_name;
+       if (*pce && (*pce)->ce_flags & ZEND_ACC_INTERFACE) {
                return "implement interface ";
        } else {
                return "be an instance of ";
@@ -518,21 +519,22 @@
        }
 
        cur_arg_info = &zf->common.arg_info[arg_num-1];
+    if (cur_arg_info->class_name.v) {
+        zstr class_name;
 
-       if (cur_arg_info->class_name.v) {
-               if (!arg) {
-                       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);
-               }
-               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);
-               }
+        if (!arg) {
+            need_msg = zend_verify_arg_class_kind(cur_arg_info, &class_name, 
&ce TSRMLS_CC);
+            return zend_verify_arg_error(zf, arg_num, cur_arg_info, need_msg, 
class_name, "none", EMPTY_ZSTR TSRMLS_CC);
+        }
+        if (Z_TYPE_P(arg) == IS_OBJECT) {
+            need_msg = zend_verify_arg_class_kind(cur_arg_info, &class_name, 
&ce TSRMLS_CC);
+            if (!ce || !instanceof_function(Z_OBJCE_P(arg), ce TSRMLS_CC)) {
+                return zend_verify_arg_error(zf, arg_num, cur_arg_info, 
need_msg, class_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, &class_name, 
&ce TSRMLS_CC);
+            return zend_verify_arg_error(zf, arg_num, cur_arg_info, need_msg, 
class_name, zend_zval_type_name(arg), EMPTY_ZSTR TSRMLS_CC);
+        }
        } else if (cur_arg_info->array_type_hint) {
                if (!arg) {
                        return zend_verify_arg_error(zf, arg_num, cur_arg_info, 
"be an array", EMPTY_ZSTR, "none", EMPTY_ZSTR TSRMLS_CC);
http://cvs.php.net/viewvc.cgi/php-src/tests/classes/type_hinting_002.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/tests/classes/type_hinting_002.phpt
diff -u php-src/tests/classes/type_hinting_002.phpt:1.1 
php-src/tests/classes/type_hinting_002.phpt:1.2
--- php-src/tests/classes/type_hinting_002.phpt:1.1     Sat Mar 27 15:49:23 2004
+++ php-src/tests/classes/type_hinting_002.phpt Mon Oct  2 11:05:02 2006
@@ -13,5 +13,4 @@
 $o->a($o);
 ?>
 --EXPECTF--
-
-Fatal error: Class 'NonExisting' not found in %stype_hinting_002.php on line %d
+Catchable fatal error: Argument 1 passed to Foo::a() must be an instance of 
NonExisting, instance of Foo given, called in %s on line %d and defined in %s 
on line %d

http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/bug39003.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/bug39003.phpt
+++ ZendEngine2/tests/bug39003.phpt
--TEST--
Bug #39003 (__autoload() is called for type hinting)
--FILE--
<?php

class ClassName
{
        public $var = 'bla';
}

function test (OtherClassName $object) { }

function __autoload($class)
{
    var_dump("__autload($class)");
}

$obj = new ClassName;
test($obj);

echo "Done\n";
?>
--EXPECTF--     
Catchable fatal error: Argument 1 passed to test() must be an instance of 
OtherClassName, instance of ClassName given, called in %s on line %d and 
defined in %s on line %d

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

Reply via email to