Skip to content

Commit

Permalink
Fix incorrect line number of constant in constant expression
Browse files Browse the repository at this point in the history
Fixes GH-10356
  • Loading branch information
iluuu1994 committed Feb 2, 2023
1 parent 35a36b1 commit 848a6e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Zend/tests/gh10356.phpt
@@ -0,0 +1,20 @@
--TEST--
GH-10356: Incorrect line number of constant in constant expression
--FILE--
<?php

final class Foo {
public static $foo = [
'foo' => DOES_NOT_EXIST,
];
}

new Foo();

?>
--EXPECTF--
Fatal error: Uncaught Error: Undefined constant "DOES_NOT_EXIST" in %s:5
Stack trace:
#0 %s(%d): [constant expression]()
#1 {main}
thrown in %s on line 5
1 change: 1 addition & 0 deletions Zend/zend_compile.c
Expand Up @@ -10005,6 +10005,7 @@ static void zend_compile_const_expr_const(zend_ast **ast_ptr) /* {{{ */
return;
}

CG(zend_lineno) = zend_ast_get_lineno(ast);
zend_ast_destroy(ast);
*ast_ptr = zend_ast_create_constant(resolved_name,
!is_fully_qualified && FC(current_namespace) ? IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE : 0);
Expand Down

0 comments on commit 848a6e5

Please sign in to comment.