1

Are there any way for me to use PHP to parse information of a PHP file, something likes : what functions/classes it has, which functions are built-in/user-defined or how many variables are there....?

Charles
  • 50,943
  • 13
  • 104
  • 142
Teiv
  • 2,605
  • 10
  • 39
  • 48
  • 1
    More useful than just the raw token stream is a parser class like http://pear.php.net/package/PHP_Parser (or even CodeSniffer) which deciphers defined functions/variables. – mario Mar 13 '11 at 02:34

1 Answers1

3

You can use the function token_get_all() to parse PHP source.

$source = file_get_contents('my-file.php');
$tokens = token_get_all($source);
Andrew Moore
  • 93,497
  • 30
  • 163
  • 175
  • 1
    There was also some discussion about this here: http://stackoverflow.com/questions/5068007/parsing-and-printing-php-code/ – Tom Gruner Mar 13 '11 at 02:20