From 848a6e5035a540113722b988e40083e5632bf9b7 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Thu, 2 Feb 2023 19:49:40 +0100 Subject: [PATCH] Fix incorrect line number of constant in constant expression Fixes GH-10356 --- Zend/tests/gh10356.phpt | 20 ++++++++++++++++++++ Zend/zend_compile.c | 1 + 2 files changed, 21 insertions(+) create mode 100644 Zend/tests/gh10356.phpt 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);