News for hackers. Stuff that matters.
Re:An Exceptional Change in PHP 7.0 by amyjess on Monday October 05, 2015 @05:50PM (#10335244)
Out of curiosity, why does PHP use backslashes in throwable names?
Re:An Exceptional Change in PHP 7.0 by wvenable on Monday October 05, 2015 @05:55PM (#10335281)
The backslash is the namespace separator. This just indicates that these classes are in the root namespace. This is the same as prefixing :: in front of C++ class names.
Re:An Exceptional Change in PHP 7.0 by alexbilbie on Monday October 05, 2015 @06:03PM (#10335333)
This is the official explanation as to why the delimiter is a backslash - https://wiki.php.net/rfc/namespaceseparator
Re:An Exceptional Change in PHP 7.0 by hahainternet on Monday October 05, 2015 @06:32PM (#10335491)
To this day, the table on that page remains one of my favourite examples of PHP's badly thought out design.
Re:An Exceptional Change in PHP 7.0 by wvenable on Monday October 05, 2015 @06:35PM (#10335513)
PHPs design and grammar precluded using any of the other existing operators. The backslash is really the best choice and in practice it works pretty well. The actual debate on the separator choice was very very very long.
Re:An Exceptional Change in PHP 7.0 by sarciszewski on Monday October 05, 2015 @08:44PM (#10336073)
Yeah, and also: Who gives a shit? It's the convention they chose, just adapt to it and get over it, or program in a different language.

People who like to complain about PHP are rarely the same people who use it every day.

Re:An Exceptional Change in PHP 7.0 by deckar01 on Monday October 05, 2015 @10:05PM (#10336357)
I have to use PHP every day and I rarely go a day without complaining about it.
Re:An Exceptional Change in PHP 7.0 by sarciszewski on Monday October 05, 2015 @10:21PM (#10336401)
You're the exception, not the rule.

I mostly hear C/C++, Ruby, Python, etc. devs complain about PHP. Very rarely actual PHP developers.

And typically, their complaints are less of the moan-ass "waaah, they use a \ for namespace separation" and more "ugh, why don't they disabled emulated prepared statements by default"?

Only one side is constructive.

Re:An Exceptional Change in PHP 7.0 by kazinator on Tuesday October 06, 2015 @12:32PM (#10340094)
None of those who are complaining about the monument of shit being erected outside of town is actually an erector of monuments made of shit.

Typically, their complaints are about the ugly appearance and smell.

Only one side is constructive.

Re:An Exceptional Change in PHP 7.0 by ufo on Monday October 05, 2015 @08:22PM (#10335986)
I still don't get what stopped them from using any of the existing operators.
Re:An Exceptional Change in PHP 7.0 by teh_klev on Monday October 05, 2015 @09:06PM (#10336163)
Rationale was discussed on IRC, see:

https://wiki.php.net/_media/rfc/php.ns.txt

Linked to at the bottom of:

https://wiki.php.net/rfc/namespaceseparator

Re:An Exceptional Change in PHP 7.0 by ufo on Monday October 05, 2015 @09:48PM (#10336318)
I skimmed through it but couldn't really understand why they couldn't coopt one of the existing operators (for example, by making classes have a namespace for their methods)

Couldn't they provide a clearer explanation than simply dumping a huge IRC log like that??

Re:An Exceptional Change in PHP 7.0 by wvenable on Monday October 05, 2015 @10:34PM (#10336442)
Basically namespaces operate at a different level. You can almost imagine it like Macro expansion -- the namespaces are fully resolved for all the symbols in the file and then the compilation happens. This is necessary for a host of reasons. They can't co-opt an existing operator because all the existing operators work at an entirely different level.
Re:An Exceptional Change in PHP 7.0 by debacle on Monday October 05, 2015 @09:45PM (#10336307)
The reality is that the parser is absolute shit and that sort of necessitated the character not being '.'

But you get used to that kind of stuff writing PHP. At least Facebook is making things better.

Re:An Exceptional Change in PHP 7.0 by MrBuddyCasino on Monday October 05, 2015 @06:33PM (#10335498)
I'm 99% sure this isn't satire.
Re:An Exceptional Change in PHP 7.0 by dguaraglia on Monday October 05, 2015 @06:33PM (#10335499)
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?)

Re:An Exceptional Change in PHP 7.0 by wvenable on Monday October 05, 2015 @06:42PM (#10335538)
> 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.

Re:An Exceptional Change in PHP 7.0 by lucio on Monday October 05, 2015 @07:27PM (#10335725)
if 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.
Re:An Exceptional Change in PHP 7.0 by Washuu on Monday October 05, 2015 @06:42PM (#10335537)
The 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.
Re:An Exceptional Change in PHP 7.0 by kijin on Monday October 05, 2015 @10:40PM (#10336456)
Modern 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.