Skip to content

Fix property fetch on magic constants in constant expressions #9172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Zend/tests/gh9136.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
GH-9136: Assertion when fetching property of magic constant in constant expression
--FILE--
<?php

const C = __file__->foo;

?>
--EXPECTF--
Warning: Attempt to read property "foo" on string in %s on line %d
11 changes: 11 additions & 0 deletions Zend/tests/gh9138.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--TEST--
GH-9138: NULL pointer dereference when fetching property of "bad" list in constant expression
--FILE--
<?php

#[Attribute([,]->e)]
class Foo {}

?>
--EXPECTF--
Fatal error: Cannot use empty array elements in arrays in %s on line %d
4 changes: 4 additions & 0 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -10616,6 +10616,10 @@ static void zend_eval_const_expr(zend_ast **ast_ptr) /* {{{ */
case ZEND_AST_CONST_ENUM_INIT:
zend_eval_const_expr(&ast->child[2]);
return;
case ZEND_AST_PROP:
zend_eval_const_expr(&ast->child[0]);
zend_eval_const_expr(&ast->child[1]);
return;
default:
return;
}
Expand Down