From: Antony Dovgal Date: Mon, 2 Oct 2006 11:05:02 +0000 (+0000) Subject: fix #39003 (__autoload() is called for type hinting) X-Git-Tag: RELEASE_1_0_0RC1~1484 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=36b78b78a404cd68a40a6308f1d5681f22587fdc;p=php fix #39003 (__autoload() is called for type hinting) --- diff --git a/Zend/tests/bug39003.phpt b/Zend/tests/bug39003.phpt new file mode 100644 index 0000000000..7a3da849bd --- /dev/null +++ b/Zend/tests/bug39003.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #39003 (__autoload() is called for type hinting) +--FILE-- + +--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 diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 3c3decd313..ce83765809 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -472,11 +472,12 @@ 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) +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 @@ 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]; - - 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 (cur_arg_info->class_name.v) { + zstr class_name; + + 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); diff --git a/tests/classes/type_hinting_002.phpt b/tests/classes/type_hinting_002.phpt index 4cb75b1b8f..7c685bfdba 100755 --- a/tests/classes/type_hinting_002.phpt +++ b/tests/classes/type_hinting_002.phpt @@ -13,5 +13,4 @@ $o = new Foo; $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