4 ms·
Here is an example of an ambiguous case: // classes.php ///// namespace foo::bar; function baz() {} namespace foo; class bar { static function baz() {} }
by KrisJordan 17y ago
Here is an example of an ambiguous case:
// classes.php /////
namespace foo::bar;
function baz() {}
namespace foo;
class bar { static function baz() {} }
// someotherfile.php /////
include('classes.php');
foo::bar::baz(); // Ambiguity
/////
A proposed work around for the ambiguity was being explicit about ambiguous cases.
The internals team wanted to do ::, they did ::, and they convinced themselves otherwise (and suffered through a lot of pain in the process).
[17:00:05] <@CelloG> I am the strongest advocate for :: - every patch I have made up to this one was designed to preserve it, and I am convinced it just isn't technically possible to use it
http://wiki.php.net/rfc/backslashnamespaces#resolution_of_t_string_t_paamayim_nekudotayim_t_string_and_why_this_kills_as_namespace_separator http://wiki.php.net/rfc/backslashnamespaces#resolution_of_t_...
- wvenable 17y agoI've read that link and I understand it. They treat namespace access and static class access as different things. If they were the same, and namespaces and classes shared the same hash, and static class access and namespace access where the same (like in C++) this would be a non-issue. As for your ambiguity, it's a simple name clash. On the second declaration, you should get an error because foo::bar is already defined. You know, like you would in C++.
- encoderer 17y agoAhhh, I gotcha... Honestly, I hope you can put your pride aside for a moment and think about this. Under your scheme, if you were to create a namespace foo, you couldn't have a class named foo in any namespace in your application.
- wvenable 17y agoUmmm, no. In C++, classes are looked up the same as namespaces, you can have a namespace called foo::foo::foo::foo which contains a class called foo! The only restriction is that you can't have a class or namespace with the exact same fully qualified name. That's a perfectly reasonable restriction. The whole purpose of namespaces is so you can have a class called foo in a different namespace from another class called foo.
- encoderer 17y agoIt doesn't change the fact that, the way you're suggesting, I cannot have both a namespace and class named foo in the global scope or within the same namespace. if I did, I'd see the same ambiguity the PHP internals developers were discussing. And spin it however you'd like, having a namespace conflict with a classname is far more confusing than trying to wrap your head around this (apprently) insanely complex use of the backslash operator as a namespace delimiter.
- wvenable 17y agoI cannot have both a namespace and class named foo in the global scope or within the same namespace. Yes, but you make that sound like a bad thing. In real life, having classes and namespaces with the same names would not be good. Nobody is going to do it, so why support it? Can you think of an example where it makes sense to have a class and namespace with the same name? And spin it however you'd like, having a namespace conflict with a classname is far more confusing Really? Because that's how every other language works from Java, C#, C++, Perl, etc. If you didn't know that, it's probably not such a big deal.