Skip to content

Commit 115e928

Browse files
committed
Fix segfault with scalar passed to typehint with not loaded class
1 parent f58ebb3 commit 115e928

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Inexistent class as typehint receiving scalar argument
3+
--FILE--
4+
<?php
5+
6+
function foo(bar $ex) {}
7+
foo(null);
8+
9+
?>
10+
--EXPECTF--
11+
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
12+
Stack trace:
13+
#0 %s(%d): foo(NULL)
14+
#1 {main}
15+
thrown in %s on line %d
16+

Zend/zend_execute.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,11 @@ static zend_always_inline int zend_verify_arg_type(zend_function *zf, uint32_t a
780780
} else {
781781
ce = zend_verify_arg_class_kind(cur_arg_info);
782782
if (UNEXPECTED(!ce)) {
783-
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);
783+
if (Z_TYPE_P(arg) == IS_OBJECT) {
784+
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);
785+
} else {
786+
zend_verify_arg_error(zf, arg_num, "be an instance of ", cur_arg_info->class_name->val, "", zend_zval_type_name(arg), arg);
787+
}
784788
return 0;
785789
}
786790
*cache_slot = (void*)ce;

0 commit comments

Comments
 (0)