Hi Martin,

On Dec 21, 2007 8:30 PM, Martin Alterisio <[EMAIL PROTECTED]> wrote:
> I've been pondering about how to algorithmically/mechanically prepare a non
> namespaced code for namespaces appliance. This would be a first step which
> will just prepare the code for namespaces in a safe way, but not to profit
> from aliases created by use. The latest will have to be implemented manually
> (IMHO).

phc (www.phpcompiler.org) would be suitable for this purpose. It has
good support for nearly all of the features you need.


> I've come up with the following, for an organization model of a class per
> file.
> Please review.
>
> 1) find the class definition and reduce the class name to namespace/class
> 2) add namespace declaration on top of file
> 3) replace class name in definition with short name

So far this would be trivial.

> 4) find all function calls (not method calls) which are not keywords (array,
> isset, unset, list, etc) and prefix them with ::

list, array etc wouldnt be confused with functions. Functions are just
methods without target. You'd need a short list of functions such as
empty, unset etc to avoid.

> 5) find all class names (static method calls (no self:: nor parent::), new,
> catch, type hints, instanceof, extends, implements) and:

All of these are trivial.

> 5a) replace separator used (possibly: _) with namespace separator (::)
> 5b) IF the class has no namespace (ie global namespace) prefix the class
> name with ::
> 5c) IF the namespace of the class starts with the same namespace found in
> (1), remove it or prefix it with namespace::
>       (although this is not necessary)

This would be easy too.

> 6) find static method calls with variables used as class name, and mark them
> for user handled refactoring

I'm not sure why this couldnt be done automatically, but finding
static method calls is also easy. You could add comments to mark these
fairly easily.

> 7) find internal functions that use callables (call_user_func, array_map,
> array_filter, etc) and mark them for user handled refactoring

A lot of this could be automated, but there would of course be some
which would require marking.


> Later on, a methodical way of adding use statements for reducing the class
> names used, can be implemented. Although this might be more complicate than
> it seems if the method has to be careful to avoid creating possible name
> clashes.
>
> If anyone has a comment on this, I'll be more than grateful if you share.


If you need any advice, on this, please let me know.


Paul

-- 
Paul Biggar
[EMAIL PROTECTED]

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to