What's __halt_compiler in PHP for?

前端 未结 3 1721
谎友^
谎友^ 2020-12-23 17:19

From the manual:

void __halt_compiler ( void )

This function halts the execution of the compiler. This can be useful to embe

3条回答
  •  情歌与酒
    2020-12-23 17:52

    Assume you have one script with some php code and lots and lots of binary clutter.

    then you want the compiler to NOT try to parse the binary because if there is somewhere in the binary it would break.

    The point is being able to just ship one file with binary data and php code.

    For a little example see this blog post


    So you want not only to stop the execution of a script (like exit() would) but to stop the parsing so that you can have "invalid syntax" at the end of file and php still can execute the first part.


    Another example:

    This will get parsed as valid php and execute just fine:

    To access the data:

    This will output §RW$FG$%ZDS$TSG$TSZ%U(); §$"§%"§$!!();

提交回复
热议问题