__HALT_COMPILER() can only be used from the outermost scope
Description
__HALT_COMPILER() stops the compiler at the exact point it is encountered; everything that follows in the file is no longer parsed as PHP code but kept as raw data, readable through the COMPILER_HALT_OFFSET constant and a file handle on the same script. Because it changes how the rest of the file is interpreted, it is only meaningful once, at the very top level of the file, and cannot be placed inside a function, a class, a conditional block, or any other nested structure.
Example
<?php
function boot() {
__halt_compiler();
}
boot();
?>
Alternatives
- Move the __halt_compiler() call out of the function/class/block, to the outermost level of the file.
Related error messages
Changed Behavior
This error may appear following an evolution in behavior, in previous versions. See