From bdf5202b134708866d45c5b1d7ea3704efabd2bf Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Wed, 13 Aug 2025 15:23:42 +0200 Subject: [PATCH 1/2] Fix "Constant already defined" warning with repeated inclusion of file with __halt_compiler() Fixes GH-18850 --- Zend/tests/constants/gh18850.inc | 5 +++++ Zend/tests/constants/gh18850.phpt | 12 ++++++++++++ Zend/zend_compile.c | 6 +++++- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/constants/gh18850.inc create mode 100644 Zend/tests/constants/gh18850.phpt diff --git a/Zend/tests/constants/gh18850.inc b/Zend/tests/constants/gh18850.inc new file mode 100644 index 0000000000000..08099278ea3f2 --- /dev/null +++ b/Zend/tests/constants/gh18850.inc @@ -0,0 +1,5 @@ + +--EXPECT-- +int(62) +int(62) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index d8fb26e17768d..db611be49ab45 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -9752,7 +9752,11 @@ static void zend_compile_halt_compiler(zend_ast *ast) /* {{{ */ name = zend_mangle_property_name(const_name, sizeof(const_name) - 1, ZSTR_VAL(filename), ZSTR_LEN(filename), 0); - zend_register_long_constant(ZSTR_VAL(name), ZSTR_LEN(name), offset, 0, 0); + /* Avoid repeated declaration of the __COMPILER_HALT_OFFSET__ constant in + * case this file was already included. */ + if (!zend_hash_find(EG(zend_constants), name)) { + zend_register_long_constant(ZSTR_VAL(name), ZSTR_LEN(name), offset, 0, 0); + } zend_string_release_ex(name, 0); } /* }}} */ From 0dc0bb0e31113799cfe8a7442baca419abd87d9a Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Wed, 13 Aug 2025 18:27:12 +0200 Subject: [PATCH 2/2] Fix test --- ext/phar/tests/bug77432.phpt | 2 -- 1 file changed, 2 deletions(-) diff --git a/ext/phar/tests/bug77432.phpt b/ext/phar/tests/bug77432.phpt index b3b927a5439df..3e3a9988c7dca 100644 --- a/ext/phar/tests/bug77432.phpt +++ b/ext/phar/tests/bug77432.phpt @@ -38,8 +38,6 @@ include("phar://" . $filename); --- Include 1 --- hello world --- Include 2 --- - -Warning: Constant already defined in %s on line %d hello world --- After unlink ---