I\'m maintaining library written for PHP 5.2 and I\'d like to create PHP 5.3-namespaced version of it. However, I\'d also keep non-namespaced version up to date until PHP 5.
This is a followup to my previous answer:
The namespace simulation code got quite stable. I already can get symfony2 to work (some problems still, but basically). Though there is still some stuff missing like variable namespace resolution for all cases apart from new $class
.
Now I wrote a script which will iterate recursively through a directory and process all files: http://github.com/nikic/prephp/blob/master/prephp/namespacePortR.php
Your classnames mustn't contain the _
character. If they do, classnames could get ambiguous while converting.
Your code mustn't redeclare any global functions or constants within a namespace. Thus it is ensured that all your code may be resolved at compile-time.
Basically these are the only restrictions to your code. Though I should note that in a default configuration the namespacePortR will not resolve things like $className = 'Some\\NS\\Class'; new $className
, because it would require inserting additional code. It's better that this is patched up later (either manually or using an automated patching system.)
As we have made the assumption that no global function or constant is redeclared in a namespace you must set the assumeGlobal
class constant in the namespace listener. In the same file set the SEPARATOR
constant to _
.
In the namespacePortR change the configuration block to satisfy your needs.
PS: The script may be provided a ?skip=int
option. This tells it to skip the first int
files. You should not need it, if you have set the override mode to intelligent.