diff --git a/NEWS b/NEWS index 75d6d1f09f7..77c1e32ff3a 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,10 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? ????, PHP 8.5.0beta2 +- Core: + . Fixed bug GH-18850 (Repeated inclusion of file with __halt_compiler() + triggers "Constant already defined" warning). (ilutov) + - ODBC: . Remove ODBCVER and assume ODBC 3.5. (Calvin Buckley) diff --git a/Zend/tests/constants/gh18850.inc b/Zend/tests/constants/gh18850.inc new file mode 100644 index 00000000000..08099278ea3 --- /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 d8fb26e1776..db611be49ab 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); } /* }}} */ diff --git a/ext/phar/tests/bug77432.phpt b/ext/phar/tests/bug77432.phpt index b3b927a5439..3e3a9988c7d 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 ---