Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Is there a better way of determining a file's namespace than stripping it out using file functions? Reflection doesn't seem to help.
- * --Anatai
- */
- /* file.php */
- <?php
- namespace foo;
- // rest of file here
- ?>
- /* index.php */
- <?php
- $h = fopen('file.php', 'r') or die('wtf');
- $n = '';
- while (!feof($h) && !$n)
- {
- $l = fgets($h);
- if (stripos($l, 'namespace') !== false) $n = preg_replace('/namespace\ +(\w+);/i', '$1', $l);
- }
- fclose($h);
- print $n ? trim($n) : 'Nothing found';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment