Skip to content

Commit 7149362

Browse files
committed
Fix GH-17234: Numeric parent hook call fails with assertion
The current code expects the property name to be a string, but it can also be a number via the {} syntax. Handle this consistently to a string by using zval_get_string which will do the type coercion and refcount update (instead of assuming string and doing an explicit string copy). Closes GH-17236.
1 parent 2860c3d commit 7149362

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.4.4
44

5+
- Core:
6+
. Fixed bug GH-17234 (Numeric parent hook call fails with assertion).
7+
(nielsdos)
8+
59
- FTP:
610
. Fixed bug GH-16800 (ftp functions can abort with EINTR). (nielsdos)
711

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
GH-17234 (Numeric parent hook call fails with assertion)
3+
--FILE--
4+
<?php
5+
class ParentC {}
6+
class Child extends ParentC {
7+
public $a {
8+
get {
9+
return parent::${0}::get ();
10+
}
11+
}
12+
}
13+
?>
14+
--EXPECTF--
15+
Fatal error: Must not use parent::$0::get() in a different property ($a) in %s on line %d

Zend/zend_compile.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -5098,7 +5098,8 @@ static bool zend_compile_parent_property_hook_call(znode *result, zend_ast *ast,
50985098
zend_error_noreturn(E_COMPILE_ERROR, "Cannot create Closure for parent property hook call");
50995099
}
51005100

5101-
zend_string *property_name = zend_ast_get_str(class_ast->child[1]);
5101+
zval *property_hook_name_zv = zend_ast_get_zval(class_ast->child[1]);
5102+
zend_string *property_name = zval_get_string(property_hook_name_zv);
51025103
zend_string *hook_name = zend_ast_get_str(method_ast);
51035104
zend_property_hook_kind hook_kind = zend_get_property_hook_kind_from_name(hook_name);
51045105
ZEND_ASSERT(hook_kind != (uint32_t)-1);
@@ -5122,7 +5123,6 @@ static bool zend_compile_parent_property_hook_call(znode *result, zend_ast *ast,
51225123
zend_op *opline = get_next_op();
51235124
opline->opcode = ZEND_INIT_PARENT_PROPERTY_HOOK_CALL;
51245125
opline->op1_type = IS_CONST;
5125-
zend_string_copy(property_name);
51265126
opline->op1.constant = zend_add_literal_string(&property_name);
51275127
opline->op2.num = hook_kind;
51285128

0 commit comments

Comments
 (0)