What are some practical uses of PHP tokenizer?

后端 未结 8 1007
暖寄归人
暖寄归人 2021-02-02 11:25

What are practical and day-to-day usage examples of PHP Tokenizer ?

Has anyone used this?

8条回答
  •  再見小時候
    2021-02-02 11:36

    I use PHP_CodeSniffer for coding style compliance, which is built on the tokeniser. Also, some frameworks (e.g. Symfony 2) use the tokeniser to generate cache files or intermediate class files of PHP code. It's also possible to use the tokeniser to build a source code formatter or syntax highlighter.

    Basically, anywhere you use PHP code as data you can use the tokeniser. It's much more reliable that trying to parse PHP code with regular expressions or other string processing functions.

提交回复
热议问题