Skip to content

Commit 9c754ba

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix "Constant already defined" warning with repeated inclusion of file with __halt_compiler()
2 parents 359f442 + 708d8e9 commit 9c754ba

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.5.0beta2
44

5+
- Core:
6+
. Fixed bug GH-18850 (Repeated inclusion of file with __halt_compiler()
7+
triggers "Constant already defined" warning). (ilutov)
8+
59
- ODBC:
610
. Remove ODBCVER and assume ODBC 3.5. (Calvin Buckley)
711

Zend/tests/constants/gh18850.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
var_dump(__COMPILER_HALT_OFFSET__);
4+
5+
__halt_compiler();

Zend/tests/constants/gh18850.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
GH-18850: Repeated inclusion of file with __halt_compiler() triggers "Constant already defined" warning
3+
--FILE--
4+
<?php
5+
6+
require __DIR__ . '/gh18850.inc';
7+
require __DIR__ . '/gh18850.inc';
8+
9+
?>
10+
--EXPECT--
11+
int(62)
12+
int(62)

Zend/zend_compile.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9752,7 +9752,11 @@ static void zend_compile_halt_compiler(zend_ast *ast) /* {{{ */
97529752
name = zend_mangle_property_name(const_name, sizeof(const_name) - 1,
97539753
ZSTR_VAL(filename), ZSTR_LEN(filename), 0);
97549754

9755-
zend_register_long_constant(ZSTR_VAL(name), ZSTR_LEN(name), offset, 0, 0);
9755+
/* Avoid repeated declaration of the __COMPILER_HALT_OFFSET__ constant in
9756+
* case this file was already included. */
9757+
if (!zend_hash_find(EG(zend_constants), name)) {
9758+
zend_register_long_constant(ZSTR_VAL(name), ZSTR_LEN(name), offset, 0, 0);
9759+
}
97569760
zend_string_release_ex(name, 0);
97579761
}
97589762
/* }}} */

ext/phar/tests/bug77432.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ include("phar://" . $filename);
3838
--- Include 1 ---
3939
hello world
4040
--- Include 2 ---
41-
42-
Warning: Constant already defined in %s on line %d
4341
hello world
4442
--- After unlink ---
4543

0 commit comments

Comments
 (0)