Re: true namespaces, yet another point of view
| From: | jvlad | Date: | Mon, 29 Sep 2008 18:58:21 +0000 |
| Subject: | Re: true namespaces, yet another point of view | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-40794@lists.php.net to get a copy of this message | ||
>>> For those that do not understand very well the explanation of jvlad...
>>>
>>> He's suggesting to change the class struct to be an scope struct, and
>>> have a property that tells if it's a namespace or a class, and reuse
>>> the implementation of class which already works very well.
>>> The nested support is achieved afai understand through the Adjacency
>>> List algorithm... can you confirm this to me?
>>
>>
>> or just leave the organization of things to classes (with long class
>> names with a nice prefix to prevent collissions) and leave it to
>> class_alias() (and equivalent features for functions .. also with the
>> option of a compile time aliasing) to handle the aliasing.
>>
>> this removes the need for namespaces and use statements, while making it
>> possible to make class/function names short (that are long for
>> organizational and collision prevention reasons).
>
> Hi,
>
> This approach doesn't work because aliasing with class_alias() does not
> allow name conflicts:
>
> <?php
> class foo {
> function __construct(){echo 'hi',"\n";}}
> class_alias('foo', 'XMLReader');
> $a = new XMLReader;
> ?>
>
> results in:
>
> Warning: Cannot redeclare class XMLReader in
> /home/cellog/workspace/php5/test.php on line 4
>
><?php
>class foo {
>function __construct(){echo 'hi',"\n";}}
>use ::foo as XMLReader;
>$a = new XMLReader;
>?>
>
>results in:
>
>hi
I'm sorry I don't see anything related to namespaces in the sample. It looks
like just a trick that allows to bypass restrictions imposed on
class_alias(). If you need to provide a clear way on creating your very own
XMLReader class in the global namespace, while the class with the same name
is already registered by an extension, why not to create
remove_class()/unregister_class() and/or replace_class() functions which
will legitimate class removal/overriding?
Still not sure if it's needed at all. With namespaces, you can create your
own little world inside your private namespace and have as many overrided
classes as you want. Why bother with global namespace?