You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PHP Warning: Constant already defined when processing multiple sources with __halt_compiler() #18850
Whenever PHP processes more then one __halt_compiler() statement in one session, it emits this cryptic warning:
PHP Warning: Constant already defined in ...
Note the empty constant name.
There are several ways to trigger this. Here's one:
# echo '<?php __halt_compiler();' >inc.php
# php -a
php > include('inc.php');
php > include('inc.php');
PHP Warning: Constant already defined in /tmp/inc.php on line 1
php -v
PHP 8.0.30-master-850_prod-centos (cli) (built: Nov 2 2023 08:51:55) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.30-dev, Copyright (c) Zend Technologies
php -r "eval('?><?php __halt_compiler();'); eval('?><?php __halt_compiler();');"
Warning: Constant already defined in Command line code(1) : eval()'d code on line 1
This design is really just dubious, so I'm not sure this can be fixed without replacing the constant with a function, like compiler_halt_get_last_offset(). So, I'm tending towards closing this as a #wontfix.
I'd honestly expect __COMPILER_HALT_OFFSET__ to work like __FILE__ - i.e. you'd get the offset of the current file. (Which you might then assign to a variable or something.)
Actually, yes, you are right. __COMPILER_HALT_OFFSET__ is mangled with the current file name. So, suppressing the warning might be feasible after all, given that __halt_compiler(); will always occur in the same place for a given file.
Activity
Sannis commentedon Jun 23, 2025
Confirm this with 8.0.30:
iluuu1994 commentedon Jun 23, 2025
Thanks for the report.
This is because
__halt_compiler()also declares the__COMPILER_HALT_OFFSET__constant:https://www.php.net/manual/en/function.halt-compiler.php
This design is really just dubious, so I'm not sure this can be fixed without replacing the constant with a function, like
compiler_halt_get_last_offset(). So, I'm tending towards closing this as a #wontfix.ProgerXP commentedon Jun 23, 2025
Why not just avoid declaring
__COMPILER_HALT_OFFSET__if it's already declared? Any approach is better then the current obscure warning.iluuu1994 commentedon Jun 23, 2025
Not necessarily. If you expect
__COMPILER_HALT_OFFSET__to be something else, then no warning is not better.bwoebi commentedon Jun 23, 2025
I'd honestly expect
__COMPILER_HALT_OFFSET__to work like__FILE__- i.e. you'd get the offset of the current file. (Which you might then assign to a variable or something.)iluuu1994 commentedon Jun 23, 2025
Might be sensible. However, any such change here is breaking. As such, this will at least require some discussion.
ProgerXP commentedon Jun 23, 2025
Doesn't it already work like that?
iluuu1994 commentedon Jun 23, 2025
Actually, yes, you are right.
__COMPILER_HALT_OFFSET__is mangled with the current file name. So, suppressing the warning might be feasible after all, given that__halt_compiler();will always occur in the same place for a given file.Fix "Constant already defined" warning with repeated inclusion of fil…
Fix "Constant already defined" warning with repeated inclusion of fil…