5 ms·
Is it just me, or is the namespace syntax HORRIFICALLY ugly? Couldn't they just overload the "::" syntax or something? Maybe ":::"? Every time I look at an exa
by intranation 17y ago
Is it just me, or is the namespace syntax HORRIFICALLY ugly?
Couldn't they just overload the "::" syntax or something? Maybe ":::"? Every time I look at an example I feel like something is being escaped.
EDIT: the reasoning as to why "\" is here:
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_...
- crad 17y agomynamespace\function() && call_user_func("mynamespace\\function") FTL. Seriously shows a lack of good judgement by the people implementing new functionality.
- troels 17y ago"::" wouldn't work, because it's ambiguous at compile time. Personally I would have preferred ":::", but at some point it turned into a [bike-shed discussion](http://www.bikeshed.com/ http://www.bikeshed.com/), and then a few of the core developers made a judgement call. I don't think they realised how controversial a choice they'd made, or perhaps they just didn't think it through, but once the pick was made, there was really no turning back, because of the politics. That's php core for you, and honestly I think it's a major flaw of php. It's sort of the same way that GOTO entered the language too.
- wvenable 17y ago> "::" wouldn't work, because it's ambiguous at compile time. Why is "::" ambiguous at compile time? It seems to me something is rotten here. C++ using :: for both namespaces and static access of classes. Why didn't PHP go the same way? I never complain about the choice of operator, I complain about it's need to exist in the first place. :: would have done the job just fine, just as it does in C++, which is where they stole it from in the first place.
- Scriptor 17y agoFor some reason the PHP developers think it should be Ok to have a class in your code with the same name as a namespace you're using. I just tested this out with Python and it seems that doing the same thing simply gives you what was last defined, so if you have import lib and then class lib you will just end up with lib as being the class. Frankly, it's insulting to me that the PHP team doesn't think I have the skills needed to not name my classes after namespace I imported.
- dryicerx 17y agoThe scope resolution operator :: comes directly from C++ world which is standard practice...
- wvenable 17y agoI'm not sure I fully get the explanation from your EDIT. If you had a single scope resolution operator ::, classes and namespaces should share the same hash and lookup. A class is, fundamentally, a namespace. namespace foo; function bar(){echo "func\n";} class foo{ static function bar(){echo "func\n";} } Should be equivalent as far as invoking them is concerned.