Re: true namespaces, yet another point of view
| From: | jvlad | Date: | Wed, 24 Sep 2008 14:32:43 +0000 |
| Subject: | Re: true namespaces, yet another point of view | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-40668@lists.php.net to get a copy of this message | ||
""Guilherme Blanco"" <guilhermeblanco@gmail.com> wrote in message
news:bcb7aa500809231617y3305b5bcn18f47630a8124e0d@mail.gmail.com...
> 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?
>
> Just trying to be more clear to those that do not understand... if my
> words are greek now.... GIYF (Google Is Your Friend).
>
Yep. Thanks Guilherme for such a short explanation.
(sorry my english is quite poor and not always clear enough)
Namespaces create ambiguity with classes in php (which is a dynamic language
btw) just because their natures are very close. Beside the other great
things, class is intended to isolate its methods and properties, or group
them together. Namespace is mostly for the same purposes. It should isolate
classes as well as all other user-land entities or group them together. From
the end-user perspectives, in most cases it does not really matter if a
particular value is stored as a static property of a class or as a global
variable in a namespace. Same goes for the static method of a class vs
function in the namespace. What's important is to know the scope name. If
user uses a variable myentity::$var, it's safficient to lookup for myentity
sub-scope in the current scope, then lookup for $var in the found (or just
created) sub-scope. You see, it's not always needed to distinguish classes
vs namespaces.
In some cases the namespace can be resolved in the compile-time. For example
if the namespace is already defined, so it's known to be namespace and
therefore compiler should be smart enough to make early binding. For the
cases when namespace is referenced in the script beforehand, so it's not
known whether it is a namespace or a class, it can be resolved with
late-binding, using absolutely the same technique as php uses for for
resolving the classes.
I'm sure this is an efficient way of implementing namespaces in php and with
this implementation they will be very useful.
jv