From the manual:
void __halt_compiler ( void )
This function halts the execution of the compiler. This can be useful to embe
Previously, The ClassGenerator in the PhpSpec unit testing library provided a good example of using __halt_compiler()
, which the PHP class contains a code template for a PHP class.
They've recently update to read the template from a seperate file, but initially the getTemplate()
method will attempt to read the PHP code template provided in the file that follows the __halt_compiler()
call. This avoids the token from getting parsed.
/**
* The Class Generator is responsible for generating the classes from a resource
* in the appropriate folder using the template provided
*/
class ClassGenerator
{
//...
/**
* @return string
*/
protected function getTemplate()
{
return file_get_contents(__FILE__, null, null, __COMPILER_HALT_OFFSET__);
}
}
__halt_compiler();