Perhaps it is easier to use the PHP tokenizer instead of a regular expression. Simply walk over the list of tokens looking for T_NAMESPACE and T_CLASS.
Example (untested):
$map = array();
$tokens = token_get_all($source_code);
$namespace = 'GLOBAL';
foreach ($tokens as $token) {
if (!is_string($token)) {
list($id, $text) = $token;
if ($id == T_NAMESPACE) {
$namespace = $text;
}
if ($id == T_CLASS) {
$map[$namespace] = $text;
}
}
}
print_r($map);
Sander Marechal
2009-07-17 09:09:01