Today my objective is to retrieve all PHP class names associated with their namespace names but I got stuck. Here is an example of what I have:
$content =<<<END
<?php
namespace test;
class a { }
class b { }
namespace foo;
class bar { }
?>
END;
preg_match_all('~^\s*((?:namespace)\s+(\w+);)?\s*(?:abstract\s+|final\s+)?(?:class|interface)\s+(\w+)~mi', $content, $classes);
var_dump($classes);
The expression works only if there is at most one class in namespace but I can't figure out how to make it match all classes according to namespace.