diff --git a/Zend/tests/gh10356.phpt b/Zend/tests/gh10356.phpt new file mode 100644 index 0000000000000..2a5418bc98e09 --- /dev/null +++ b/Zend/tests/gh10356.phpt @@ -0,0 +1,20 @@ +--TEST-- +GH-10356: Incorrect line number of constant in constant expression +--FILE-- + 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 diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index dcadf6eef6d08..61e87a52919f6 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -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);