Skip to content

Commit 7b43d81

Browse files
committed
Also fix ?-> on magic consts in const expressions
Fixes GH-9136 Fixes GH-9138
1 parent 60ace13 commit 7b43d81

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

Zend/tests/gh9136_2.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
GH-9136: Assertion when fetching property of magic constant in constant expression with nullsafe operator
3+
--FILE--
4+
<?php
5+
6+
const C = __file__?->foo;
7+
8+
?>
9+
--EXPECTF--
10+
Warning: Attempt to read property "foo" on string in %s on line %d

Zend/tests/gh9138_2.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
GH-9138: NULL pointer dereference when fetching property of "bad" list in constant expression with nullsafe operator
3+
--FILE--
4+
<?php
5+
6+
#[Attribute([,]?->e)]
7+
class Foo {}
8+
9+
?>
10+
--EXPECTF--
11+
Fatal error: Cannot use empty array elements in arrays in %s on line %d

Zend/zend_compile.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10631,6 +10631,7 @@ static void zend_eval_const_expr(zend_ast **ast_ptr) /* {{{ */
1063110631
zend_eval_const_expr(&ast->child[2]);
1063210632
return;
1063310633
case ZEND_AST_PROP:
10634+
case ZEND_AST_NULLSAFE_PROP:
1063410635
zend_eval_const_expr(&ast->child[0]);
1063510636
zend_eval_const_expr(&ast->child[1]);
1063610637
return;

0 commit comments

Comments
 (0)