Poll: PHP's Latest Namespace Controversy
Moderator: General Moderators
- volomike
- Forum Regular
- Posts: 633
- Joined: Wed Jan 16, 2008 9:04 am
- Location: Myrtle Beach, South Carolina, USA
Poll: PHP's Latest Namespace Controversy
As you may have heard, the core PHP team have made a decision on how to implement the namespace separator. They chose:
\
\
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Poll: PHP's Latest Namespace Controversy
I think :: made the most sense because it followed the current usage of accessing names statically in classes. it is the best conceptual match. I know there were some cases where there was ambiguity, but they are not showstoppers to me -- no different than the current Python implementation.
Honestly, namespaces is a marginally useful feature that seems to be clamored for by a small group of programmers who claim it is the mark of a serious language.
Honestly, namespaces is a marginally useful feature that seems to be clamored for by a small group of programmers who claim it is the mark of a serious language.
(#10850)
Re: Poll: PHP's Latest Namespace Controversy
I disagree that its a marginally useful feature, but I also don't really think PHP needs them. We've been faking them with class prefixes and its worked fine. If you want namespaces, use python.
That's my opinion anyway.
Re: Poll: PHP's Latest Namespace Controversy
I would have preferred '::' and take the static issue with it.
Re: Poll: PHP's Latest Namespace Controversy
.
Because I've used it with other languages
Because I've used it with other languages
There are 10 types of people in this world, those who understand binary and those who don't
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Poll: PHP's Latest Namespace Controversy
Can't because . is the concatenation operator. Can't switch the concatenation operator to + because variables are typeless. The + converts to numeric, whereas . converts to string.VladSun wrote:.
Because I've used it with other languages
(#10850)
Re: Poll: PHP's Latest Namespace Controversy
Why is it included in the poll then?
There are 10 types of people in this world, those who understand binary and those who don't
- Bill H
- DevNet Resident
- Posts: 1136
- Joined: Sat Jun 01, 2002 10:16 am
- Location: San Diego CA
- Contact:
Re: Poll: PHP's Latest Namespace Controversy
I'm with the '::' crowd, but I can't really explain. Just my sense of it. Probably senility.
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Poll: PHP's Latest Namespace Controversy
I would have personally gone with ::: or ::
Agreed. Seeing as most PHP frameworks and projects use their own class name prefixes and it's become standard practice...why are namespaces really needed? Honestly I have never used them or needed them in PHP.Honestly, namespaces is a marginally useful feature that seems to be clamored for by a small group of programmers who claim it is the mark of a serious language.
-
crazycoders
- Forum Contributor
- Posts: 260
- Joined: Tue Oct 28, 2008 7:48 am
- Location: Montreal, Qc, Canada
Re: Poll: PHP's Latest Namespace Controversy
:: could have been a good idea, but depending on the compiler structure, it is sometimes not possible and would require too much change
I agree with \ more than the others because \ means "sub" in several contexts. (Networking, filesystems, listing of elements, etc) A namespace\function means a lot and cannot be confused with the :: operator when only the namespace and class is provided. If you see this:
$a = new facebook::user($facebookid);
//What did we intend really here? Create a new user from the facebook namespace? Or use the user function in the facebook class to return the name of a class that is sent to the new operator?
$a = facebook::getUser($facebookid);
//And here? Call the static function getUser from the facebook class? Or call a global function defined in the facebook namespace?
$a = new facebook::getUser($facebookid);
//And here, what are we doing? Creating a getUser object from a facebook namespace? Or did we intend to call the getUser function from the facebook class in a static way? It could have been a typo?
All these would result in logical or hard to spot errors because they are prone to ambiguous results and namespaces are here to prevent ambiguous code constructs.
$a = new facebook\user::getUser($facebookid);
//Much easier to read, you have no doubt here, the user wans to create a new object from the class name returned by the static function getUser from the class user in the facebook namespace... No ambiguities possible.
$a = facebook\getUser($facebookid);
//No doubt here again, we are calling getUser in the facebook namespace... not a static function of a facebook class;
crazyone out
I agree with \ more than the others because \ means "sub" in several contexts. (Networking, filesystems, listing of elements, etc) A namespace\function means a lot and cannot be confused with the :: operator when only the namespace and class is provided. If you see this:
$a = new facebook::user($facebookid);
//What did we intend really here? Create a new user from the facebook namespace? Or use the user function in the facebook class to return the name of a class that is sent to the new operator?
$a = facebook::getUser($facebookid);
//And here? Call the static function getUser from the facebook class? Or call a global function defined in the facebook namespace?
$a = new facebook::getUser($facebookid);
//And here, what are we doing? Creating a getUser object from a facebook namespace? Or did we intend to call the getUser function from the facebook class in a static way? It could have been a typo?
All these would result in logical or hard to spot errors because they are prone to ambiguous results and namespaces are here to prevent ambiguous code constructs.
$a = new facebook\user::getUser($facebookid);
//Much easier to read, you have no doubt here, the user wans to create a new object from the class name returned by the static function getUser from the class user in the facebook namespace... No ambiguities possible.
$a = facebook\getUser($facebookid);
//No doubt here again, we are calling getUser in the facebook namespace... not a static function of a facebook class;
crazyone out
Re: Poll: PHP's Latest Namespace Controversy
In fact, I would have preferred to have strict type variables and operator overloading in PHP instead of having "strict type operators". I would have preferred to have strict mode (as in Perl), so some errors are shown at "compile" (a pseudo one) time.arborint wrote:Can't because . is the concatenation operator. Can't switch the concatenation operator to + because variables are typeless. The + converts to numeric, whereas . converts to string.VladSun wrote:.
Because I've used it with other languages
Last edited by VladSun on Tue Oct 28, 2008 8:40 pm, edited 1 time in total.
There are 10 types of people in this world, those who understand binary and those who don't
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Poll: PHP's Latest Namespace Controversy
Absolutely yes...In fact, I would have preferred to have strict type variables and operator overloading in PHP instead of having "strict type operators". I would have preferred to have strict mode (as in Perl), so some errors are showed at "compile" (a pseudo one) time.