Skip to content

Commit 848a6e5

Browse files
committed
Fix incorrect line number of constant in constant expression
Fixes GH-10356
1 parent 35a36b1 commit 848a6e5

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Zend/tests/gh10356.phpt

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
GH-10356: Incorrect line number of constant in constant expression
3+
--FILE--
4+
<?php
5+
6+
final class Foo {
7+
public static $foo = [
8+
'foo' => DOES_NOT_EXIST,
9+
];
10+
}
11+
12+
new Foo();
13+
14+
?>
15+
--EXPECTF--
16+
Fatal error: Uncaught Error: Undefined constant "DOES_NOT_EXIST" in %s:5
17+
Stack trace:
18+
#0 %s(%d): [constant expression]()
19+
#1 {main}
20+
thrown in %s on line 5

Zend/zend_compile.c

+1
Original file line numberDiff line numberDiff line change
@@ -10005,6 +10005,7 @@ static void zend_compile_const_expr_const(zend_ast **ast_ptr) /* {{{ */
1000510005
return;
1000610006
}
1000710007

10008+
CG(zend_lineno) = zend_ast_get_lineno(ast);
1000810009
zend_ast_destroy(ast);
1000910010
*ast_ptr = zend_ast_create_constant(resolved_name,
1001010011
!is_fully_qualified && FC(current_namespace) ? IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE : 0);

0 commit comments

Comments
 (0)