What are some practical uses of PHP tokenizer?

Jatin Dhoot picture Jatin Dhoot · Apr 20, 2011 · Viewed 14.3k times · Source

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

Has anyone used this?

Answer

Sander Marechal picture Sander Marechal · Apr 20, 2011

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.