on Oct 26th, 2008Set sail for fail (php namespaces)

On this: http://news.php.net/php.internals/41374

ClassFile.php

namespace Foo;
class tBar {
     function loader() {
     }
}

Bootstrap.php

include "ClassFile.php";
spl_autoload_register(array("Foo\tBar", "loader"));

Will register “Foo[tab]Bar::loader”. Yes there are workarounds such as \\ or ‘, but I thought that some of the requirements were:

typo-vulnerability (\ becomes even more - in a very bad way - context sensitive within strings)
parse-ability (\t will be highlighted in most editors as an escape sequence)
IDE compatibility (same as above)

All aboard the php.internals failboat.

69 Responses to “Set sail for fail (php namespaces)”

  1. moodhon 26 Oct 2008 at 1:57 am

    setting sail for fail!

  2. Leonon 26 Oct 2008 at 2:00 am

    for the love of god, no

  3. Seldaekon 26 Oct 2008 at 2:06 am

    > spl_autoload_register(array(”Foo\tBar”, “loader”));

    But you are in fault for naming a class tBar in the first place, “Foo\TBar” will evaluate as Foo\TBar properly.

  4. Fredrik Holmströmon 26 Oct 2008 at 2:07 am

    Seldaek: So php is instead forcing an implicit naming convention of class/method/namespace names in some places? As if that would be better ;<

  5. Seldaekon 26 Oct 2008 at 3:17 am

    Well I am not all sold on the backspace either, but since it’s not going to change, I don’t think complaining is such a good idea. The internals folks knew very well that there was no perfect choice and that some people would be pissed no matter which solution they picked. Now either we just get used to it in silence or we start bitching and the less knowledgeable php guys will read that and join the party, triggering a huge mess and new “myths” about how this and that are just awfully wrong in php for this and that stupid reason.

    Anyway yes, you might have a point about the IDEs, maybe even for the \t (and others) even though I have yet to see a class name that doesn’t follow the Class convention.

    And sorry for the rant, it’s not really against you directly, I just don’t want this to turn into a massive shitstorm that will pollute all aggregators for months.

  6. Ision 26 Oct 2008 at 3:56 am

    My main problem with this is what problem were they trying to solve. What was wrong with :: for namespaces? I just fell on this story via digg and didn’t even know there was a change happening.

  7. jdzzleon 26 Oct 2008 at 5:40 am

    I for one welcome a decent namespace mechanism in php.. as far as I know, the only alternative at this point has been to use multiple require/includes …

    I’m sure there are indeed very many good reasons for choosing backslash.. at least it makes a little sense, which is more than I can say for certain perl variables, etc.. also, I know all the people who develop in windows won’t mind..

  8. marcoon 26 Oct 2008 at 6:30 am

    @jdzzle

    There is no good reason. Something like this happens when you shoot down all the other ideas you had and this is what you are left with.

  9. Joe Blowon 26 Oct 2008 at 7:06 am

    Quote your namespace strings with single quotes, guys. Not that hard.

  10. pffwaton 26 Oct 2008 at 8:00 am

    Symbolic of the whole php culture really.

  11. Arse Banditon 26 Oct 2008 at 8:07 am

    @Joe Blow: It is hard to remember when you’ve got a whole bunch of other esoteric bullshit to think of.

    Just when you thought it couldn’t get any worse, PHP lowers the bar again.

  12. mrkrison 26 Oct 2008 at 9:05 am

    PHP was already far behind in terms of design and functionality. This just adds to it and encourages people to move to Python/Ruby.

  13. Nick Stinemateson 26 Oct 2008 at 9:06 am

    Wow. Terrible.

  14. mercpandaon 26 Oct 2008 at 9:07 am

    Seriously. WTF. In my mind, the backslash is pretty much for escaping. That’s its singular function in my mind. It’s just… not friendly on the eyes.

    This is what happens when you don’t focus on programmer happiness (Ruby) or human readability (Python), and instead focus on petty criteria (type-ability, typo-vulnerability, parse-ability, IDE compatibility, number of chars - really? you have so little faith in your developers that you can’t overcome these?). You get ugly\ass\language\decisions.

  15. Robert Græsdalon 26 Oct 2008 at 10:23 am

    This specific example won’t be much of a problem. Use single quotes instead of double:

    spl_autoload_register(array(’Foo\tBar’, ‘loader’));

  16. Arse Banditon 26 Oct 2008 at 11:07 am

    > This specific example won’t be much of a problem. Use single quotes instead of double:

    Robert G: you’re missing the point, a language should not have such a messed-up design in the first place that the programmers using it have to use lame hacks.

    Not only that, but *my mind* parses:
    Foo\tBar
    as
    Foo[tab]Bar

    Not to mention how many times a newbie is going to be caught out by this and get a really indeciferable and obscure error message. The answer is to use :: this works well for C++, which just raises an _easily understood_ error message when there is a name collision.

    This is an utterly terrible design decision, I think it marks the last nail in PHP’s coffin.

  17. Jarlyon 26 Oct 2008 at 12:57 pm

    Someone posted this one another blog about this which I totally felt too:

    > OMG. I had to check if this wasn’t a joke the first time I read this. I actually makes me feel ill

  18. Anonymous Cowardon 26 Oct 2008 at 1:03 pm

    Concepts from WTF-designers for WFT-programmers. And they all end up at thedailywtf…

    Same bullshit with PHP6 . Last time I looked, the plan was not to implement “undeclared properties” warnings. The reason: backward compatibilities (Don’t hurt the WTF-programmers!). It’s actually in the PHP5-Code right now, but commented out…

  19. OtengiMon 26 Oct 2008 at 1:14 pm

    This totally SUCKS!!. Please let the :: for namespaces if not PHP namespaces will be a mess to work. That approach feels like a hack. It is not practical or elegant.

  20. OtengiMon 26 Oct 2008 at 1:24 pm

    After this IMHO even Perl is better language designed, I knew it that PHP is just a Hack and very ugly one. Good luck PHP folks but me I think is time to leave this boat and go with Python. Python is awesome designed a pretty neat language.

  21. Stan Vassilevon 26 Oct 2008 at 1:55 pm

    If editors highlight “\t” as an escape sequence, as you yourself said, one would think this would make you correct your typo and make it “\\t”.

    But somehow you marked this as a disadvantage.

  22. markon 26 Oct 2008 at 4:41 pm

    The PHP developers must smoke something that is dangerous.

    They want to trumpet on perl’s past bad decisions. Although even perl is better designed.

    People should switch to ruby, or python, or both. PHP is set to just fail.

    PS: Using \ as selector is UGLY.

  23. Jooston 26 Oct 2008 at 5:21 pm

    These \ namespaces sound like a late April Fools joke :(

  24. OtengiMon 26 Oct 2008 at 6:07 pm

    Sorry for many posts but this is not tolerable for PHP.

    It is a fine language but this put in a shame situation. PHP community should make changes and get a proper language designer. Really even can ask to people as Guido Van Rosum or Anders Hejlsberg to give a tip or advice on how to fix this mess of language.

    This is very disappointing.

  25. Jarlyon 26 Oct 2008 at 6:31 pm

    This is hilarious in a sad way.

    It feels like someone had a bright moment:

    While (See foot){
    Pull out gun;
    Aim;
    shoot!!;
    }

  26. TSeekeron 26 Oct 2008 at 6:38 pm

    They should have chosen to use æ or þ while they were at it.

    Quite seriously tho, on the “type-ability” point of view, which is one of the PHP dev’s criterions, their choice denotes a very US-centric view. Everyone’s got an US keyboard, right?… WRONG! I’d much rather type : twice, or even a dot as far as key combinations are concerned, than the dreaded “Alt-Gr + 8″ combo.

    As you pointed out, using “\” as the namespace separator is also calling for typos and “weird PHP features that should be called ‘bugs’ but aren’t” (your example being very accurate).

    PHP has been annoying me for a while, this is the latest of a long string of really bad design choices.

  27. spotmanon 26 Oct 2008 at 6:55 pm

    I agree - this is probably the nail in PHP’s coffin. While there is more than one way to accomplish anything in code, this can not be seen as an improvement, but just another facet/issue in PHP that people will complain about and be confused over. Especially rookie developers that are learning from php4 and 5 code, when they see this it will be confusing. This will raise the learning curve of php (which is already higher than something like python/ruby/django/rails) and paint php even more in the light that it is an aging language with numbered days.

  28. Charleson 26 Oct 2008 at 7:00 pm

    Two steps forward, one step back.

    At least we’re getting closures in 5.3 to make up for the stupidity of the backslash decision.

  29. Chrison 26 Oct 2008 at 7:24 pm

    [17:59:52] johannes_: is there some problem with \ and notepad?

    Lol, PHP coders are notepad jockeys.

  30. […] блоге дяденьки эмоподобной внешности обсуждаются отрицательные стороны принятого решения. В комментах […]

  31. Renon 26 Oct 2008 at 7:48 pm

    Surely you have to fix the parser before you get to this point.

    I also want to know what happens when they want to add another new feature that requires a token.

  32. Nicolason 26 Oct 2008 at 8:55 pm

    Time to move to haXe (http://haxe.org) !

  33. […] If you were to load a class or a namespace dynamically by referencing it in a string, you’d have to take care to escape your backslash: […]

  34. Tanaon 26 Oct 2008 at 9:15 pm

    Two words: Brain damage.

    I mean, BACKSLASH?! Oh, dear God no. It’s not April, is it?

    \ isn’t even ON the majority of European keyboards. And it’s the Universal Control Character of Doom, including the one you use inside PHP’s own strings, and in databases. PHP already has quite enough trouble with backslashes as it is so naturally, what do you do? Let’s make it the namespace operator! What could go wrong? *facepalm*

    Should we fork the language to take it out of the hands of the idiots — I’m not going to mince words here, _idiots_ — who thought this was a good idea, or should we just sod it all and let the rats jump off this failboat of a language for much faster Lua, or make Python or Ruby faster, or write a new language that’s actually great at server-side web applications?

    Hell with it — I’d take Javascript over this. If I wanted brain-damage, I’d be writing COBOL. No more PHP for me.

  35. Tyleron 26 Oct 2008 at 9:19 pm

    You honestly shouldn’t be using double quotes where you don’t need them. Using double quotes makes the parser look for variables and escaped characters, which takes more time and in this case you don’t need, and in fact does the opposite of what you want.

    Get into the habit of using single quotes while concatenating variables and escaped characters. You should have been doing that from the start of learning PHP. It’s almost always faster that way.

    But still, the backslash is a dumbass choice.

  36. […] Еще по теме: здесь и здесь. […]

  37. Ivanon 26 Oct 2008 at 10:55 pm

    A language gets namespaces. What, is it 1980 or something? *checks-the-calender*

    When PHP will be 100% multiplatform? 2020?

    Ah, excuse me, I forgot. PHP is great! It allows you to violate the “seperation of concerns” concept by allowing to mix code, HTML, and sql requests.

  38. […] same place on different keyboard layouts. Is this a choice that is biased toward certain users? One blogger has referred to the backspace choice as a decision that will cause PHP to “set sail for […]

  39. Nick Ashleyon 26 Oct 2008 at 11:41 pm

    I kind of understand where you are coming from with keeping a familiar syntax across languages, but don’t know how much weight I would put on that. If every programming language had the same syntax for everything, except PHP was the odd man out, then you would definitely have a point. However every language has there own way to do things like string concatenation, testing equality, or ending statements. Adding namespacing to the mix isn’t that big of a deal IMHO.

    I feel that it would be even harder to learn the language when syntax means two different things. People would be confused saying “I thought that was how you accessed a static function, not a namespace!”. With the backslash, you have a standard way to do everything. Also, I feel you SHOULD be using single quotes, thus eliminating the escaping issue. However, the escaping is a standard way to do things when working with double quotes as well. Why would this confuse them?

    Also, I love the people calling this a “hack”. How is using a backslash for the syntax a “hack”. What are they hacking at, exactly?

  40. johnon 26 Oct 2008 at 11:42 pm

    I like :: because it is on the home row on at least US-layout keyboards. People who can type properly tend to care about that. Real keyboards have the Ctrl key on the home row for the same reason, and if not, xmodmap to the rescue! Fail indeed. Very glad I switched to Perl in 1999 :-)

  41. Nick Ashleyon 26 Oct 2008 at 11:43 pm

    Whoop, my reply might not make a whole lot of sense because I meant to reply to a webpage in another tab, on the same subject:
    http://ninh.nl/blog/2008/10/25/a-word-on-phps-upcoming-namespace-seperator/

  42. […] The PHP folks have finally announced that PHP will get namespacing in the form of . The universal escape character. They really should have went with the standard :: or ::: Using ‘’ is going to work well. […]

  43. Kent Fredricon 27 Oct 2008 at 1:58 am

    Next thing they’ll be wondering how to make this work

    class Foo { public static function bar(){”print 1″; } }
    class Foo { public static function bar(){”print 2″; } }

    Which is tantamount to lunacy. You simply don’t use the same token in the same scope, and create an error when you do, or, you use the lexical ordering of the scopes to define the precedence.

    In other languages, creating a class that shadows a namespace causes a type error. Its just not supposed to be done.

    They should use the tried and true :: delimiter, and just bar collisions from happening, because at least that way anything that *does* go wrong wont cause intricate escaping problems all over the place that just *adds* to Phps current number one problem of security.

    Time to get off the fail boat and get on with perl. At least its a mature language thats had everything php’s *trying* to get without being perl for goodness knows how long.

  44. Kurton 27 Oct 2008 at 2:31 am

    Isn’t there a problem with something else if you really need to use namespaces in your PHP application? Like a bad architecture choice decision?

  45. OtengiMon 27 Oct 2008 at 5:21 am

    PHP was not a designed language, It does not have a spec is just a hack. What do you spec from it?.

    I encourage people not to feed any more PHP hype because really PHP is garbage, period.

    Try another alternatives as Python, Perl or Ruby that are well designed still have flaws but are much better than this PHP garbage.

    PHP jumped to the sharks.

  46. Fennecon 27 Oct 2008 at 5:41 am

    Kurt: “Isn’t there a problem with something else if you really need to use namespaces in your PHP application? Like a bad architecture choice decision?”

    What??
    Doing a medium-big-sized project without namespaces is… possible, but tedious at best and insane at worst. Why would you want to give up organization, and separation of unrelated chunks of code, for a big globbed-together mess where anything on one side of the app could be calling anything else on the other unintentionally?

    If by a “bad architecture choice decision” you mean “choosing PHP for a large application”, sure, I’ll agree, using PHP namespaces is a bad idea. :P Other than that…

  47. Fennecon 27 Oct 2008 at 5:43 am

    Kurt: “Isn’t there a problem with something else if you really need to use namespaces in your PHP application? Like a bad architecture choice decision?”

    What??
    Doing a medium-big-sized project without namespaces is… possible, but tedious at best and insane at worst. Why would you want to give up organization, and separation of unrelated chunks of code, for a big globbed-together mess where anything on one side of the app could be calling anything else on the other unintentionally?

    If by a “bad architecture choice decision” you mean “choosing PHP for a large application”, sure, I’ll agree, using PHP namespaces is a bad idea. :P Other than that, to suggest they are something to be avoided on principle is lunacy.

  48. Rekonstrukcia Kupelneon 27 Oct 2008 at 7:43 am

    You’ve got to be kidding me! ‘::’ and ‘.’, there’s nothing else to choose from. Anyone heard of the rule of least surprise?

  49. […] 2. http://news.php.net/php.internals/41374 3. http://loveandtheft.org/2008/10/26/set-sail-for-fail-php-namespaces/ 4. http://wiki.php.net/rfc/namespaceseparator Popularity: unranked [?] Listen to this podcast […]

  50. Fishmongeron 27 Oct 2008 at 9:44 am

    I have the inside track on the decision. It was devised with a very straightforward and standard method for language designers.

    Get one small rodent or cat, a Lithuanian dumb terminal keyword and a box large enough to hold the keyboard. Combine the them all together for 30 seconds. You may need to shake the box a little if you don’t get enough generated ideas the first time. In this case the developers were given.

    1) qweru
    2) *51
    4) hy7r667^%&%
    \n\r 5)
    6) [BACKSLASH]***

    *** The blog software used by this page can’t can’t currently embed native backslashes and so replaces them with [BACKSLASH]

    1) was rejected on the grounds it was too close to Lithuanian for cheese and would make developers too hungry. 2) was their favored option but 51 was deemed too unlucky for one of the committee. 3) managed to delete itself. 4) sounds like the devil when spoked phonetically in Mongol.

    5) was a
    bit too

    irritating.

    And so I now hope you see why they chose 6) The only logical option.

  51. Moon 27 Oct 2008 at 10:00 am

    I must say, this is one of the more insane decisions the PHP core developers have made recently.

    To my mind, the ‘ambiguity’ over using :: is only an issue if you have no rules of precedence, which would be nuts. There was no reason to come up with an alternative in the first place.

  52. Adeason 27 Oct 2008 at 1:10 pm

    Oh for love of god NO!

    This must be the most stupid thing in PHP until now.

  53. PHP is developed by morons - LinLogon 27 Oct 2008 at 4:43 pm

    […] guys.The Slashdot article also linked to an interesting consequence of the choice of backslash: it has the potential to mess up referencing classes in strings. So if your class starts with, say, the letter "t" or "n", you’re going to have […]

  54. NSK Nikolaos S. Karastathison 27 Oct 2008 at 5:42 pm

    It must be a DOS conspiracy, I can’t explain it any better :)

    Seriously, though, it is generally a good idea to use single quotes.

  55. Daniel Ritchieon 27 Oct 2008 at 9:23 pm

    “parse-ability (\t will be highlighted in most editors as an escape sequence)”

    http://www.honestlyillustrated.com/off-site/screenshots/stop-flailing-about-php-namespace.png

    Not true, and besides, it’s a built in function, same as print(), and functions always arbitrarily control their interpretation (parsing) of their input parameters. PHP is a function library, as well as a language. Welcome to programing, enjoy your stay. :\

  56. […] 经过开发者几个小时的讨论后,他们决定采用 “” 作为分隔符,而不是更流行的“ :: ”。Fredrik Holmström指出了这种分隔方法可能会产生的问题,如打字出错(但不会出现错误提示),IDE兼容性问题,字符数字等等,好处则是容易输入和分析。” […]

  57. […] Holmström points out another flaw with the backslash, as well, but many commenters note that the internals team knew […]

  58. oogmssrson 28 Oct 2008 at 9:15 pm

    oogmssrs…

    oogmssrs…

  59. Alkis Doulgerison 05 Nov 2008 at 2:49 pm

    Looks like a bad joke, or more precisely, a nightmare. I am using php for 8 years, and waiting for the final php 5.3 from the moment they announced the alpha version 3 months ago.

    I was sticked in using php all this years. I start thinking it was not a good decision.

    I start from today having a look on Python, just in case. I hope it won’t need to go further, watting for the people in php to do something about such terrible decisions.

    Why the heck in so many languages, the dot (.) works perfect as an

    1) object.method() declarations
    2) class.method() declations
    3) namespace separator

    at the same time???

    Why on the early days, the single colon (:) was rejected for namespaces?

    because it conflicts with the ? : syntax?

    even if we need to write:

    $someVar = ns1:SomeMethod1() ? ns2:SomeMethod2 : new ns3:SomeClass3

    - Code on the left of ? is not a problem, because it is before the “?” is parsed.
    - Since ns2 and ns3 are namespaces the parser does not expect to use them alone of course, but instead they are expected to have a “:” on their right, followed by a class,method,constant or namespace. Any other use could be by itself an error. So what is left? The alone “:” in the middle, which in such cases must be with spaces on its sides.
    That was the problem???

    Another solution would be the double dot (..). It is not used anywhere, at least that would conflict with writing namespaces.

    Php community lost lots of programmers when they were expecting namespaces in version 5.0, and it was decided to be left out.

    I think, that if that new decision remain as is, it would be worse than then

  60. Custom PHPon 12 Nov 2008 at 11:43 pm

    This is the 3rd blog I have come upon today that mentions the namespece. Someone said this will cause developers to move away from PHP.

    Interesting. What happens with all the code that is all over the place? Who will upgrade it or manage it?

  61. […] PHP最终开始支持namespace(命名空间)。 但是经过开发者几个小时的讨论后,他们决定采用 “” 作为分隔符,而不是更流行的“ :: ”。Fredrik Holmström指出了这种分隔方法可能会产生的问题,如打字出错(但不会出现错误提示),IDE兼容性问题,字符数字等等,好处则是容易输入和分析。” November 13th, 2008 in js框架 | tags: php, 命名空间 […]

  62. Ivan, Web-Impress.comon 14 Nov 2008 at 9:42 am

    I must say, this is one of the more insane decisions the PHP core developers have made recently.

    To my mind, the ‘ambiguity’ over using :: is only an issue if you have no rules of precedence, which would be nuts. There was no reason to come up with an alternative in the first place.
    Ivan, Web-Impress

  63. ozofelizon 19 Nov 2008 at 11:54 am

    Bye bye php. Hello python and ruby

  64. […] la polémica ya está servida, y las críticas no son […]

  65. Amr Mostafaon 08 Dec 2008 at 4:06 pm

    The example provided in the original post doesn’t make sense. You are using double quotes and a \t without escaping it, and what do you expect?

    I have no objection what so ever with using whatever operator out there. Backslash makes sense. Everyone is already familiar with slash (forward or backward) being a separator of some kind.

    People make it sound like the end of the world. I don’t love it either, but I to hate it, or think about it more than few minutes.

    I care about the language’s syntax. But I don’t see this new operator bringing any significant good or bad (i.e. if you already consider PHP syntax “good” or “bad”; that operator will not change it).

    People should start thinking about namespaces and how to use it to make their applications better. Instead of worrying about what character they chose for the syntax of this feature.

  66. devReview()on 19 Dec 2008 at 5:55 am

    PHP 5.3 for 2009…

    PHP 5.3 is getting closer. The third alpha release is now public. The current plan is for betas and release candidates every 3-4 weeks and a full release by the end of March 2009.
    The most high profile new feature is namespaces. This has been a while c…

  67. imobion 31 Dec 2008 at 8:28 pm

    yo…

    Thank you! I would now go on this blog every day!…

  68. domainmasteron 01 Jan 2009 at 2:29 am

    hey…

    not bad……

  69. domainmasteron 03 Jan 2009 at 12:05 pm

    hey…

    I have already seen it somethere…

Trackback URI | Comments RSS

Leave a Reply