Skip to content

Commit 966d22b

Browse files
committed
Fix property fetch on magic constants in constant expressions
Closes GH-9136 Closes GH-9138 Closes GH-9172
1 parent b576bb9 commit 966d22b

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ PHP NEWS
6262
(Tobias Bachert)
6363
. Added error_log_mode ini setting. (Mikhail Galanin)
6464
. Updated request startup messages. (Eric Norris)
65+
. Fixed GH-9136 and GH-9138 (Fixed fetching property of magic constant in
66+
constant expressions). (ilutov)
6567

6668
- COM:
6769
. Fixed bug GH-8750 (Can not create VT_ERROR variant type). (cmb)

Zend/tests/gh9136.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
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.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
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10616,6 +10616,10 @@ static void zend_eval_const_expr(zend_ast **ast_ptr) /* {{{ */
1061610616
case ZEND_AST_CONST_ENUM_INIT:
1061710617
zend_eval_const_expr(&ast->child[2]);
1061810618
return;
10619+
case ZEND_AST_PROP:
10620+
zend_eval_const_expr(&ast->child[0]);
10621+
zend_eval_const_expr(&ast->child[1]);
10622+
return;
1061910623
default:
1062010624
return;
1062110625
}

0 commit comments

Comments
 (0)