Preg_match class name from PHP file

Posted by talentedmrjones on Stack Overflow See other posts from Stack Overflow or by talentedmrjones
Published on 2010-05-03T04:58:07Z Indexed on 2010/05/03 5:18 UTC
Read the original article Hit count: 244

Filed under:
|

I have a script that recursively scans a directory pulling out class names from php files, and storing those classes names in an array. This is working nicely even through the rather large Zend Framework library folders.

The issue is that classes that extend other classes are not being included in the array.

Here is my current preg_match:

if (preg_match("/class\s*(\w*)\s*\{/i",strip_comments(file_get_contents($file)),$matches)) $classes[] = $matches[1];

I know that the last \s* is not right; there should be something there that can catch "{" or " extends Some_Other_Class {" .

© Stack Overflow or respective owner

Related posts about php

Related posts about preg-match