Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Sean Coates' Blog:
Fun With the Tokenizer...
Mar 07, 2005 @ 13:55:09

In a display of one of the more underused bits of functionality in PHP, Sean Coates has a new posting over on his blog about a simple example use of the tokenizer in PHP.

I was reminded, this past week, of how cool the tokenizer is. One of the guys who works in the same office as I do had what seemed to be a simple problem: he had a php file that contained ~50 functions, and wanted to summarize the API without parsing through the file, manually, and cutting out the function declarations.

The extension (which has been part of the PHP core distribution since 4.3.0) consists only of two functions: token_get_all and token_name, and a boatload of constants.

He goes on to show code on how one would pull the classes/functions/methods from a chunk of code and what parameters were related to each. It really is a pretty slick use of an interface that few seem to know about...

tagged:

Link:


Trending Topics: