Fix segfault with scalar passed to typehint with not loaded class

This commit is contained in:
Bob Weinand 2015-06-21 01:35:22 +02:00
parent f58ebb3609
commit 115e9288bb
2 changed files with 21 additions and 1 deletions

View file

@ -0,0 +1,16 @@
--TEST--
Inexistent class as typehint receiving scalar argument
--FILE--
<?php
function foo(bar $ex) {}
foo(null);
?>
--EXPECTF--
Fatal error: Uncaught TypeError: Argument 1 passed to foo() must be an instance of bar, null given, called in %s on line %d and defined in %s:%d
Stack trace:
#0 %s(%d): foo(NULL)
#1 {main}
thrown in %s on line %d

View file

@ -780,7 +780,11 @@ static zend_always_inline int zend_verify_arg_type(zend_function *zf, uint32_t a
} else {
ce = zend_verify_arg_class_kind(cur_arg_info);
if (UNEXPECTED(!ce)) {
zend_verify_arg_error(zf, arg_num, "be an instance of ", cur_arg_info->class_name->val, "instance of ", Z_OBJCE_P(arg)->name->val, arg);
if (Z_TYPE_P(arg) == IS_OBJECT) {
zend_verify_arg_error(zf, arg_num, "be an instance of ", cur_arg_info->class_name->val, "instance of ", Z_OBJCE_P(arg)->name->val, arg);
} else {
zend_verify_arg_error(zf, arg_num, "be an instance of ", cur_arg_info->class_name->val, "", zend_zval_type_name(arg), arg);
}
return 0;
}
*cache_slot = (void*)ce;