8 ms·
Heh, I was wondering the same. As others have pointed out, it looks like it's the namespace separator. Now someone has to explain why on Earth you need the name
by dguaraglia 11y ago
Heh, I was wondering the same. As others have pointed out, it looks like it's the namespace separator. Now someone has to explain why on Earth you need the namespace separator if these class names are already in the namespace?
PHP has an incredible knack for almost copying other languages' features, but making them uglier in some random way, for no particular added benefit.
(I know, I'm a hater... but seriously, why?)
- Washuu 11y agoThe namespace separator is not required if already in the correct scope. I am not sure why the author decided to include them in the examples.
- kijin 11y agoModern PHP code rarely uses the global namespace, so almost everyone who cares about correct handling of the new exceptions will have to prefix them with a backslash anyway.
- wvenable 11y ago> Now someone has to explain why on Earth you need the namespace separator if these class names are already in the namespace? You don't. This is just illustrating these classes are in the global namespace. > PHP has an incredible knack for almost copying other languages' features, but making them uglier in some random way, for no particular added benefit. Well you have a case for "no added benefit" typically they aren't ugly for a random reason. There's a lot of very necessary reasons for the way these things work while making a language which is still PHP. PHP isn't precompiled. PHP has autoloading of classes. PHP allows code to be imported into other code. Combining namespaces with all the other existing features isn't an easy task.
- lucio 11y agoif you do not include the namespace separator, and you import a namespace with the same name defined, you'll have a not-so-pleasant surprise. e.g.:you use "Exception" to catch all exceptions, and someone defines "SQL\Exception", then you import "SQL", and now all your catch blocks stop working. But don't worry. This is business as usual in the PHP world.