Slashdot Mirror


PHP Gets Namespace Separators, With a Twist

jeevesbond writes "PHP is finally getting support for namespaces. However, after a couple hours of conversation, the developers picked '\' as the separator, instead of the more popular '::'. Fredrik Holmström points out some problems with this approach. The criteria for selection were ease of typing and parsing, how hard it was to make a typo, IDE compatibility, and the number of characters."

85 of 523 comments (clear)

  1. Going back to DOS style... by joaommp · · Score: 5, Funny

    ... and comming full circle.

    1. Re:Going back to DOS style... by Anonymous Coward · · Score: 4, Informative

      Uhm no. Because the DOS commands used '/' for indicating options as opposed to the '-' of the UNIX world.

    2. Re:Going back to DOS style... by larry+bagina · · Score: 2, Informative

      which was based on CPM and VMS.

      --
      Do you even lift?

      These aren't the 'roids you're looking for.

    3. Re:Going back to DOS style... by joaommp · · Score: 5, Funny

      Jeez, take a joke as it is, will you?

    4. Re:Going back to DOS style... by The+Bender · · Score: 2, Insightful

      Geez, you have a website that just mirrors Wikipedia and dumps google ads all over it? You must be some kind of a business genius. Particularly since you seem to think that spamming /. will get you clicks. Bandwidth usage and hatred maybe, but clicks, nope.

    5. Re:Going back to DOS style... by eulernet · · Score: 2, Funny

      Scroll your screen to see the animation:

      \
      -
      /
      |

    6. Re:Going back to DOS style... by billcopc · · Score: 2, Insightful

      So how do you like scamming your ads off of Wikipedia's content ?

      Just when I thought the human race couldn't get any more pathetic, I get proven wrong.

      --
      -Billco, Fnarg.com
  2. Another fashionable addition for PHP: by Anonymous Coward · · Score: 4, Insightful

    PHP 5.3 also adds support for local GOTOs. This langauge is so up with the times.

    1. Re:Another fashionable addition for PHP: by lgw · · Score: 4, Insightful

      Wow, can't type today. Let's try again:

      GOTO remains the best way, in most programming languages, to exit multiple loops, branch to common clean-up code before leaving a function, etc.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    2. Re:Another fashionable addition for PHP: by coryking · · Score: 3, Insightful

      Modern languages have "exit for" or "break" to bail out of a loop.

      If you have a triple nested loop in the same function, you should refactor the code and move the inner loops into another function.

      What do you mean by "Clean Up Code"? If you have so many branches in a single function, again, refactor the code and split them into multiple functions.

      See also: Code Complete

    3. Re:Another fashionable addition for PHP: by chrysalis · · Score: 5, Insightful

      GOTO is what your CPU is actually doing 80% of the time.
      You can pump up your ego by imagining that using a language without something explicitely called "GOTO" makes your code "up with the time". But what you actually do is nothing but GOTOs, just written in a different manner.

      Ironically, the VM that PHP uses is completely GOTO-based (well, you can pick several methods at compile-time, but GOTO is what a lot of distributions chose because performance is often better than CALL and it's very stable nowadays).

      Oh and even JAVA has GOTO and relies a lot on it. The compiler hides an explicit thing called "GOTO", but what you get after compilation is full of GOTO. And it's actually why apps can actually do something.

      Laughing at "GOTO" is ignorance, or just blind trolling because you read somewhere that BASIC had a "GOTO" keyword. I guess in a few years your children will laugh at those horrible "$", "$this", "->", ":" and "\" symbols, that would remind them the old time of a language called PHP. Though you are proud of them now.

      Using temporary variables like "$should_exit", dummy loops just to "break" at the right place, or named loops to work around "break" that would only exit the first loop is nothing but writing "GOTO" in an obfuscated and inefficient way. "GOTO" is not synonym for "spaghetti code" (the famous keyword always used by people blindly repeating that GOTO is bad).

      Oh and grep for "goto" in your Linux kernel or in any BSD operating system. Wow, tons of them. Really. But I guess this is just because these source codes are shits written by people who can barely write GW-BASIC, and of course none of these operating systems actually work. Glad you are there to help. Teach them how to code, tell them that their code is so passé.

      Or shut up.

      --
      {{.sig}}
    4. Re:Another fashionable addition for PHP: by woot+account · · Score: 2, Informative

      See instead: Linus Torvalds

    5. Re:Another fashionable addition for PHP: by lgw · · Score: 4, Insightful

      Yes, for school problems, refactoring the code to make the inner loop a function is great. For real-world legacy crap code, it's often impractical. You might have 15 variables that would need to be passed into that inner loop, and you might have shop standards preventing you from passing some of those types into functions, etc, plus your boss (often rightly) object to you "refactoring" code that works today. "Refactoring" is a charmingly naive expectation for legacy crap code to begin with. And if you're not working with legacy crap code today, consider yourself lucky: you don't know how good you have it.

      And by "clean-up code" I mean: you allocate resources at the top of a function, so they must be cleaned up at the bottom of the function (and no sneaky returning from the middle of the function). That code at the bottom of the function is "clean-up code". If you have 15 possible errors in your function, you either have some unreadable mess with 15 nested if statements that hide a perfectly straightforward logic flow, *or* you branch to the clean-up code in each of the 15 error cases, making the actual logic of the function obvious.

      Of course, most coders are simply incompetant, don't even bother to check for errors, and certainly don't ensure that every resource allocated at the top is easily visually identifyable as being freed at the bottom, which is why there are so many job maintaining legacy crap code (and why Java exists in the first place).

      And of course there are languages in which "goto" is pronounced "throw" and all the clean-up happens automatically, but mostly it's inventory and payroll databases that get coded in such languages: give me legacy crap code that does something *interesting* any day! I will forever cherish the one job I had in which C++ was used correctly (not the usual typing C into a cpp file) and goto was really unnecessary, but I don't expect lighting to strike twice in my career.

      Blah, blah, Code Complete. Some of us were doing that stuff correctly long before Steve McConnell (and I'd hardly cite Microsoft as an example of a stable, secure, maintainable code base!).

      --
      Socialism: a lie told by totalitarians and believed by fools.
    6. Re:Another fashionable addition for PHP: by hawk · · Score: 2, Insightful

      Although rare, there are times when GOTO is the cleanest way out.

      I recall being stunned to run across one of them writing the code for my dissertation, and noting that I was going through a *lot* of code to avoid a single, simple GOTO. Yes, I could have avoided it, but under the circumstances, the GOTO was much cleaner.

      Oddly, I don't remember the circumstances; just my sheer amazement that such circumstances actually existed.

      hawk

    7. Re:Another fashionable addition for PHP: by lgw · · Score: 2, Informative

      In you example, F() took only two arguments, and the extra processing overhead of the function call was (presumably) not a concern. There are times when one or the other of those factors is practical. If the inner loop needs 15 variables (and is modifying some of them), the code can become far less readable than a simple goto, and noticably less performant. Of course, code performance is less of an issue every decade, but multiply nested loops are the one place where it still tends to matter.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    8. Re:Another fashionable addition for PHP: by Thuktun · · Score: 5, Insightful

      GOTO is what your CPU is actually doing 80% of the time.

      And your car's engine spends all of its time repeatedly causing small explosions with volatile petroleum.

      The driver is generally recommended to let the engine do this and not try to intervene or do it themselves.

    9. Re:Another fashionable addition for PHP: by ObsessiveMathsFreak · · Score: 4, Informative

      Goto's are useful. Labels are useful. Yes they can lead to problems, but so do things like pointers, dynamic typing, operator overloading, namespaces and automatic memory management. But they can also solve problems that are otherwise intractable, which is what the GP was trying to tell you. Dismissing them just because E. Djisktra said so is not really good enough.

      If you want an argument from authority, or just a good read, here's Donald Knuth on Structured Programming with GOTO Statements. You need to read that paper before you can have a proper opinion on the GOTO statement. Otherwise you're just adhering to dogma.

      --
      May the Maths Be with you!
    10. Re:Another fashionable addition for PHP: by logfish · · Score: 2, Interesting

      I don't agree. Goto's are terrible if you want to start multithreading things, and we all know that that is going to be the future. By scoping everything, you can help separate access and help with "threadability" (if that is even a word). Whatever people say, I'm adhering to the dogma! :)

  3. Can\'t read summary by jspenguin1 · · Score: 5, Funny

    I couldn\'t read the summary because it had an unterminated string literal.

  4. But in PHP for Windows by Anonymous Coward · · Score: 5, Funny

    It'll be /, just to keep things interesting.

  5. I have to say they are working really hard.... by A+beautiful+mind · · Score: 5, Insightful

    ...to make PHP the most retarded computer programming language on the planet.

    --
    It takes a man to suffer ignorance and smile
    Be yourself no matter what they say
    1. Re:I have to say they are working really hard.... by FooAtWFU · · Score: 5, Informative

      Oh, they've been at it for a while now ;)

      --
      The World Wide Web is dying. Soon, we shall have only the Internet.
    2. Re:I have to say they are working really hard.... by SanityInAnarchy · · Score: 2, Insightful

      That link compares PHP to Perl.

      And pretty soundly shows Perl to be as good as or better than PHP, in some fundamental ways.

      I spit on Perl and so does everybody else I know.

      You apparently don't know a lot of people who actually understand Perl.

      --
      Don't thank God, thank a doctor!
    3. Re:I have to say they are working really hard.... by SanityInAnarchy · · Score: 2, Interesting

      CGI days (only technical requirement is standard input and output) are long gone.

      Well, not really. It still works. Your biggest complaint:

      You gonna end up with huge performance problems unless you would use something more modern and advanced than trivial piping.

      That is a vertical scaling concern. If vertical scaling is that important to you, consider using C, instead.

      Not that it's unimportant. I'm just saying -- if all we had was CGI, there's no reason we couldn't still throw hardware at the problem.

      No, I was talking about things like FastCGI, or even more relevantly, in-application webservers. It turns out, talking HTTP really isn't that hard. Ruby has, by my count, six separate in-application webservers supporting the common Rack API.

      Throw a load balancer like nginx in front of them, and what do you need Apache for? Other than old apps which were tied too closely to it -- some mod_php (though those mostly tend to work with php as fcgi), and especially some mod_perl -- but that's about it.

      In other words: HTTP itself is the new CGI. And that still gives you plenty of flexibility about what you choose for an implementation language.

      Now you already can't choose/change language easily as you could in past. Service libraries and frameworks - as per project requirements - pretty much define what language one would use.

      Not many project requirements dictate specific frameworks -- and they shouldn't.

      Services, maybe, but honestly, any service that needs such a huge library that you wouldn't port it to a better platform is too complex a service, and also too rigid a library.

      --
      Don't thank God, thank a doctor!
  6. yet another wtf by larry+bagina · · Score: 3, Interesting

    The rfc claims that typing "**" is easier than typing "%%" or "^^".

    --
    Do you even lift?

    These aren't the 'roids you're looking for.

    1. Re:yet another wtf by Mental+Maelstrom · · Score: 2, Funny

      AltGr + Plus [the key right of number 0] on Estonian layout also. This is so discriminatory! :P

      We should use a character present on most keyboard layouts. I propose the use of the Space-key for this purpose.

  7. A long overdue addition by DontLickJesus · · Score: 2, Insightful

    As a developer who primarily works with C#/.Net, with a little PHP on the side, IMO this addition is long overdue. It would be nice to have a more standard separator, but when I RTFA they seem to have a just reason for it, and it's using semantics that PHP coders are used to. I will happily adjust myself in this ONE manor in order to reap the MANY benefits of namespaces.

    Just my 2 cents.

    --
    Where genius and insanity become confused true wisdom is found
    1. Re:A long overdue addition by FooAtWFU · · Score: 5, Funny

      I will happily adjust myself in this ONE manor

      While you're livin' it up at your stately manor, I'm coding PHP out of my garage, you insensitive clod!

      --
      The World Wide Web is dying. Soon, we shall have only the Internet.
    2. Re:A long overdue addition by Shados · · Score: 4, Insightful

      Thats all good. I personally feel its just easier to avoid PHP altogether and not have to adjust to all of the language's quirks for little to no benefits from other offerings. Simpler that way.

  8. Re:what wrong with by FooAtWFU · · Score: 2, Funny
    Slashcode runs off of Perl. They must hates it with a passion.

    [sic]

    --
    The World Wide Web is dying. Soon, we shall have only the Internet.
  9. Re:what wrong with by anotherone · · Score: 4, Insightful

    PHP uses the . as the concatenation operator. PHP does not support operator overloading...

    --
    Username taken, please choose another one.
  10. The BASIC of the 21st century by mangu · · Score: 5, Insightful

    I once did a lot of work on PHP. Today, when people ask me for upgrades I just migrate it to Python.

    This unfortunate choice of the escape character for namespace separator is stupid, but seems almost irrelevant to me. How many nails do they need in the PHP coffin to bury it?

    1. Re:The BASIC of the 21st century by Dragonslicer · · Score: 5, Funny

      PHP is far from dead. PHP5, with support for real OO, was a huge improvement. There's been a lot of hard work put in to PHP in the last few years to make it a much more viable modern programming language.

      Then I see people suggesting \ for a namespace separator, and I wonder what happened to all the people that put so much work into making PHP5 good, and why we can't get them back.

    2. Re:The BASIC of the 21st century by mangu · · Score: 2, Insightful

      I wonder what happened to all the people that put so much work into making PHP5 good, and why we can't get them back.

      The last one was seen downloading a Ruby On Rails development environment.

    3. Re:The BASIC of the 21st century by faraway · · Score: 2, Funny

      I don't do minor upgrades, there are other people for that. When a major upgrade is needed, let's say from version "2.7" to "3.0" they call me.

      Wow. So you're the guy that does those small changes huh? They usually call me for "3" to "4". I write it all in machine language for optimized speeds and job protection.

    4. Re:The BASIC of the 21st century by mweather · · Score: 2, Interesting

      It's not that hard to convert existing websites into Django, Pylons or TurboGears apps. Usually it's much faster than familiarizing yourself with the PHP code enough to make the needed changes.

    5. Re:The BASIC of the 21st century by Saint+Stephen · · Score: 3, Funny

      in other words you're incapable of maintaining code and you rewrite the same thing for them in a different language...

    6. Re:The BASIC of the 21st century by chrysalis · · Score: 3, Insightful

      PHP ? Real OO? Thanks for the great joke.
      How can I add methods to Number? Ehm you know, the class used for numbers... In order to write 3.times() for instance... ah, it doesn't exist? Ok, so how can add methods to strings? Impossible, strings aren't objects either?

      Stop kidding.

      Why do PHP programmers use classes for? Just to avoid collisions between two functions with the same name when files are included. Really... very few PHP code instanciates more than one object per class.

      Introduction of namespaces might limit this.

      But there's something else that PHP miss: a "static" keyword.

      Guess how very large source code like OS kernels or demos have been built in C or assembler, without namespaces, without classes, without symbols like \, but without coders constantly fighting about names collisions?

      The reason is file-local symbols, ie. the static keyword in C (and local symbols in assembler). Only export (ie. make non-static) what you need to use in other files. As a bonus, it helps the compiler in order to optimize the code.

      --
      {{.sig}}
    7. Re:The BASIC of the 21st century by Adam+Jorgensen · · Score: 2, Informative

      Erm... You sir, are a twit... Seriously... Yes, there are a lot of crap PHP coders out there. And yes, there is a lot of awful PHP code out there. As is always the case though, that is not the be all and end all. There is actually good PHP code out there, there are actually good PHP coders out there. Describing PHP as the BASIC of the 21st century is actually quite ridiculous and merely illustates that your encounters with the langauge have been limited to bad experiences rather than good ones. Also, your rant about the static keyword (Which PHP does have but which is used in a different fashion) is compltely IRRELEVANT because you are comparing apples (C) and potatoes(PHP). Just because PHP looks like C does not mean that it is C. Please reapply to the Department of Mental Affairs for a functioning brain...

  11. Backslash! by SEWilco · · Score: 3, Funny

    Just make sure they name it a backslash in the documentation, not a slash.

  12. Well now we all know what trouble this is going .. by 3seas · · Score: 4, Funny

    ... to cause for windows servers...

    imagine what directories will be deleted due to a typo!

  13. other issues by adamruck · · Score: 4, Insightful

    Maybe they could starting fixing the noun-verb vs verb-noun problems instead.

    --
    Selling software wont make you money, selling a service will.
  14. Today is a Wonderful Day by redink1 · · Score: 5, Funny

    The number of days that an old, crusty Perl developer can laugh at another language are few and far between.

    Thank you, PHP.

    1. Re:Today is a Wonderful Day by siride · · Score: 3, Interesting

      Perl once used "'" to separate package name parts. Still does for backwards compatibility. Really annoying. Oops! I love Perl, btw.

  15. Re:Well, That Does It! by Zontar+The+Mindless · · Score: 3, Insightful

    It's not just developers, it's things like IDEs which highlight anything starting with '\' as an escape sequence.

    Which - since nearly every other common programming or scripting language uses '\' to mark the beginning of an escape sequence - is something you might reasonably expect.

    Come to think of it, so does PHP... ooops...

    --
    Il n'y a pas de Planet B.
  16. Re:WTF? by ThePhilips · · Score: 4, Interesting

    You should say "thanks" they haven't chosen something else. e.g Jam (build system; make analog) uses "!" as a "platform neutral" path separator. During evaluations for new build system I joked that I oppose jam since we do not need a "platform neutral" system - we need one for *nix and cygwin. To my surprise many supported me.

    I think their decision to use '\' is very very dumb one.

    I'm still huge fan of Objective-C in that aspect. Unlike C++, which tried to marry C and objects, ObjC took more pragmatic approach: C constructs remains C constructs and object oriented constructs got new distinctive syntax so that you can never mix up what code you are looking at.

    In that aspect, I think PHP folks would regret their decision in future: '\' isn't distinctive enough and they would need to introduce more silly syntax hacks when extending language further.

    --
    All hope abandon ye who enter here.
  17. Easier on which keyboard layout? by Anonymous Coward · · Score: 5, Insightful

    How is it possible for even American developers to be this clueless. Which characters are convenient to type depends entirely on the keyboard layout that is used. Case in point, $ is insanely painful to type on Scandinavian layout.

    If your choice of characters used in your programming language is affected by how easy/hard it is to parse the code, you probably shouldn't be involved in developing a programming language.

    1. Re:Easier on which keyboard layout? by Tom · · Score: 2, Interesting

      I couldn't agree more. When I read this my only thought was "what the fuck?". On a German Mac keyboard, \ is Alt+Shift+7. I think on Linux and Windos it's something equally retarded.

      Will the people who made PHP a good programming language please fork it and take it away from the clueless morons who have taken over?

      --
      Assorted stuff I do sometimes: Lemuria.org
    2. Re:Easier on which keyboard layout? by Tom · · Score: 4, Insightful

      This line from the IRC discussion says it all:

      [16:24:51] bjori: switch to US layout ;)

      --
      Assorted stuff I do sometimes: Lemuria.org
  18. Re:Well, That Does It! by larry+bagina · · Score: 2, Interesting

    This isn't the first (or last) time PHP developers have implemented a stupid workaround rather than fixing problems with the language/runtime/interpreter/parser/scanner.

    --
    Do you even lift?

    These aren't the 'roids you're looking for.

  19. Re:WTF? by caluml · · Score: 5, Insightful

    I think their decision to use '\' is very very dumb one.

    You've summed up my opinion concisely. That is *truly* retarded to use the (almost?) universal escape character for another reason. Almost as retarded as Microsoft going with \ for a directory separator.

  20. Re:HOLY FUCKING SHIT!?!?! by coryking · · Score: 4, Informative

    Except you just made a typo. It is "\" instead.

    Either way, most languages use either "." or "::" for namespaces

    # perl looks like
    use My::CPAN::Module qw();
    my $instance = My::CPAN::Module->new("junk");

    # c# looks like
    using System.Windows.Controls;

    System.Windows.Controls.ListBox box = new System.Windows.Controls.ListBox();

    # c++ looks like (I think)
    namespace Blah::Blah;

    # php will now look like
    $object_instance = new My\PEAR\Module("myvar");

    I'll leave the "looks" of PHP's method to the reader.

  21. Classes, namespaces, and subnamespaces by janwedekind · · Score: 4, Informative

    Looking at the IRC discussion it seems that they didn't have much of a choice.

  22. Re:what wrong with by mysidia · · Score: 2, Informative

    PHP uses the . as the concatenation operator. PHP does not support operator overloading...

    You don't need operator overloading. To use the same symbol in different contexts.

    You need a parser worth its salt.

    a.one = $b.two . $a.one

    Only has one use of the concatenation operator if 'a' and 'b' are namespaces.

    A good convention is to simply require space around the concatenation operator. Or to require both operands meet the lexical conventions of a variable or string constant, for it to be interpreted as a concatenation.

    I.e. $X = $A . $B

    Is a concatenation

    $X = $A.$B

    Is a parse error

    $X = $A.B

    Is an assignment of 'X' to the 'B' variable within the 'A' namespace

  23. Re:That's because.. by SoapBox17 · · Score: 4, Insightful

    Since PHP is a weakly typed language, using + for string concatenation would introduce a number of problems. + is used numeric addition, and thus automatically converts the operands to numbers before adding them.

    So using + for string concat too would be basically impossible... When would you decide to concat the operands, and when would they be added? If you base it on the results of the string to number conversion, you get situations where the same line of code sometimes adds numbers and other times concatenates strings, or where it is impossible to concat two strings which contain only digits.

  24. Re:Gripe Moan Bitch and Holler! by SUB7IME · · Score: 3, Insightful

    Scripting languages are for those of a weak mind and poor technical skills and the singular lack of the ability to plan a system out before you write one line of code.

    Or for projects that need to be compiled at runtime. But, nice magnanimity.

  25. .NET / WPF is going this way by coryking · · Score: 2, Interesting

    At least in a sense. You can map a .NET namespace to an XML namespace. Say you have namespace that is:

    Shados.Awesome.Controls

    You can map that into:

    http://www.shados.com/controls

    In c# you'd plunk this into your AssemblyInfo.cs file:
    [XmlnsDefinition("Shadows.Awesome.Controls","http://www.shados.com/controls")]
    And thus add it to your XAML code:


    <UserControl xmlns="http://www.microsoft.com/xml/something"
    xmlns:shadow="http://www.shados.com/controls">
    <shadow:AwesomeControl x:Name="myControl" param="aParam" />
    </UserControl>

    You can even get multiple .NET namespaces to map into a single XML namespace.

  26. Re:so what's the problem here? by mysidia · · Score: 5, Informative

    The problem is not merely that it is different.

    The problem is they chose the ESCAPE character as a namespace separator.

    This is even worse than using $ as the namespace separator.

    Because of the problems it causes syntax highlighters, the problem it causes to programmer sanity when storing identifier names in a string.

    The problem it causes when searching through and sanitizing code.

    For example, since \ has a special meaning in the context of a regular expression, searching and replacing using regular expressions just got very painful.

    Copy and paste no longer works for searching and substituting.

    Refactoring just became a major bitch.

  27. Re:what wrong with by moderatorrater · · Score: 4, Insightful

    The whole purpose behind using '.' as string concatenation instead of '+' is that it eliminates ambiguity. What you're suggesting throws the ambiguity back in. Remember, if it's more complex for the parser to understand, it's more complex for a human to understand. As a programmer who moves between PHP and Javascript a lot, I can tell you that I miss being able to use a dot for objects when I'm in PHP, but the ambiguity in string concatenation/addition in javascript is an order of magnitude more annoying.

    I suspect they're doing the same thing with namespaces. The backslash isn't used for anything except escaping strings, and I doubt that's going to add any ambiguity at all. There are a lot of problems with PHP, and it's well worth your ridicule, but making sure that separate operations have separate operators isn't one of those problems.

  28. Other suggestions by lepidosteus · · Score: 3, Interesting

    For additionnal fun, read this: http://wiki.php.net/rfc/namespaceseparator

    Looks like they considered stuff like :> and :) as separators for namespace. Seriously.
    Also, they don't give any malus for tybe-ability to \ while on most european keyboards it's a lot harder than any other suggested separator. Way to go !

  29. Re:WTF? by moderatorrater · · Score: 2, Funny

    When are you going to use the escape character outside of a string? I agree that it's dumb, and it's going to make for ugly looking code, but saying that it shouldn't be used because it's an escape character seems like an empty criticism. It's like saying that Elisabeth Taylor's personal life is messed up because she doesn't pay enough attention to her hair.

  30. What about Eval? by coryking · · Score: 3, Funny

    Now do you have to escape your namespaces before passing them through eval?

    eval("$instance = new My\\Super\\Class(\"blah\"););

    Since they now are using the escape character for namespaces, I wonder what kinds of security implications this might have? What happens when a PHP program for some reason evals() some user input that doesn't properly escape the namespaces?

    1. Re:What about Eval? by prockcore · · Score: 2, Insightful

      You'd have to do that anyway, because you used double quotes, "$instance" is going to get evaluated and your eval will fail anyway.

  31. Re:so what's the problem here? by coryking · · Score: 2, Interesting

    1) "/" - used by almost all languages in regex expressions. I wouldn't want to pollute that namespace.
    2) "::" - Awesome. Many other languages do this. I think this is already taken for PHP, but I dont know PHP well enough
    3) "|" - Pipe has a very specific meaning on the command line and I'd hate to pollute that. Plus it looks ugly.
    4) "~" - Any reasons this wouldn't work?
    5) "." - Again, awesome. Many other languages use this.
    6) "!" - Used
    7) "&" - Ugly, used.
    8) "," - Why not? Does any language use the comma for anything? Might be kinda ugly though "$var = My,Class($arg1);"

  32. Re:That's because.. by coryking · · Score: 2, Insightful

    Calling a variable "myInt" doesn't make it an integer -- it was a float from the second you added a dot.
    First, duh. Second, are you sure it will return "hello1.0" and not "hello1.00" or "hello1"? I'm not, I could test to find out, but that makes my point. It adds ambeguity to the language and makes me think about something I really should be thinking about. To use your example, what does the following result in?


    function blah(arg1) {
            var blah = "10" + arg1 + 5 + "hi";
    }

    alert(blah("hi"));
    alert(blah(1));
    alert(blah("1"));

    My example isn't as contrived as yours. What if blah() was in some other JS file. It could be easy to trip the function up based on what you pass in.

    Using "." for string concatenation at least gives both you, the code reader, and the compiler a hint at what you mean. That way the compiler can barf if you do something silly like concatenate an integer with a string. Using "+" for both addition and concatenation just makes more work for both parties.

    In any case, I don't find concatenation nearly as useful as interpolation, most of the time. In Ruby, at least, interpolation is known to execute faster than concatenation. But that doesn't help you if you're using JavaScript.

    I agree with this statement. I much prefer how Ruby and Perl do it... just toss the variables into your string and it will interpolate them.

    BTW, I'm not too familiar with Ruby. Does it pull the same trick Perl does and use a different operator for string comparison?


    if($myStr eq "hi") { print "hi";}

  33. Re:what wrong with by mysidia · · Score: 2, Interesting

    The backslash isn't used for anything except escaping strings, and I doubt that's going to add any ambiguity at all.

    Oh?

    What's this going to mean?

    namespace X;
    class n{
    }
    $X\n->r = "B";
    Then later....

    $X="S";
    echo "$X\nn->r\n";

    Doing string interpolation unambiguously will be a PITA, since \ has special meaning inside a string.

    Does the "\n" delinate the end of the identifier and a carriage return, or is it being used as a namespace separator?

    I don't think they're making parsing all that easy.

    At least with lexical rules and a . operator, things can be well-defined, and not break other features of the language.

  34. Easy to fix this by sfjoe · · Score: 5, Funny

    Since PHP is open source, someone will make a fork with a different separator and the dumber of the two choices will wither away.

    --
    It's simple: I demand prosecution for torture.
  35. Re:what wrong with by moderatorrater · · Score: 5, Informative

    As I remember, everything more complex than just outputting the value of the variable (ie calling a method, accessing a property, etc) requires you to use brackets inside of the string. Namespaces would work the same way without adding any complexity that wasn't already there.

  36. Re:Phalanger by shutdown+-p+now · · Score: 2, Insightful

    Allowing unicode characters in identifiers is SICK and not to be encouraged by any programming language or any compiler for any reason, as the issues are even more widespread than with this PHP issue.

    Why, exactly? English is not the only language spoken in the world, you know, and programmers in many countries feel more at ease naming identifiers using their native language rather than trying to come up with an English translation with their limited knowledge of English. In fact, when people who don't know English well are forced to use English names in identifies, the mistranslations that result can often be very confusing - take it from someone who has to deal with such code daily. And most languages in the world require at least a few letters not in ASCII.

    By the way, have you seen Fortress programming language? You know, the one that not only allows Unicode, but uses its fully in the core library, including all standard mathematical operators (with their normal meaning). It is surprisingly readable.

    Unicode is used throughout for several years now. Programming languages are pretty much the only place where ASCII still holds, but ever since Java, this has been relaxing more and more - and rightly so. Look back 30 years - do you remember all that code written in all-uppercase because many computers of that time simply didn't have lowercase letters? And it's all gone now, because there's no longer any need to account for such machines - they don't exist anymore. Restrictions on plain ASCII only are heading the same way, and for the same reasons. All editors support Unicode now, so it is used already, and it will be used more and more.

  37. Re:PHP sucks, but it has a very important niche by msuarezalvarez · · Score: 2, Informative

    Give Haskell (or ML, Scheme, Lisp and friends) a try: using PHP to prototype algorithmically intrincate stuff is simply absurd.

  38. Re:what wrong with by mysidia · · Score: 2, Interesting
    Actually, no. You can do the following:

    <?
    class Q{
    };
    $Q->n="B";

    echo "$Q->n\nS";
    echo "$Q$Q+$Q\nX->n\n";
    ?>

    And the output in PHP 4.4.8 (version of PHP distributed in stable OSes) is:

    B
    SObjectObject+Object
    X->n

    Just like one would expect....

  39. Re:WTF? by BollocksToThis · · Score: 2, Insightful

    Given that / support has only been present in recent Windows versions, I have to say
      [citation sorely needed]

    --
    This sig is part of your complete breakfast.
  40. Re:It's all a joke by ESqVIP · · Score: 2, Interesting

    '**' is easier to type than '^^'?

    It is, once you consider some people have dead keys. Typing "^^" can become wildly different depending on what OS you're using, and result in weird behavior. On some systems/applications, the two carets are printed at once and you're back to normal editing. On others, the first one is written, but the other remains in dead-key mode. I've seen systems where this would just print a single caret (possibly coupled with a beep). Then the only reliable way on those keyboard layouts to type that symbol is to press caret, space, caret, space -- four key presses (not counting any shifting you might need to get to the caret character) for an operation which might become very common.

    Using '\' has the best parse-ability?

    Well, an unambiguous, single-character token is often easier to parse than a double-character token which might conflict with a single-character one.

    Plus they did not even evaluate '::'.

    That's what they were originally using. The problem is that they already use it for static method invocation, so there would be problems when class names and namespaces clashed. And then for some reason they decided they wanted to allow that to happen, rather than (for example) not allowing classes to have the same name as namespaces and mitigating that by using different naming conventions for both.

    But then again, the backslash isn't very easy to type either -- I'm daily switching between three different computers. On each one of them, the backslash key is in a different position. Seriously.

  41. Re:It's all a joke by corychristison · · Score: 3, Insightful

    :: is already used for static methods on classes... it would be harder to implement the differentiation of :: for namespaces and :: for static methods... especially if people started to use classes with the same name as a namespace (which is likely if all modules get their own namespace)

    I actually think that '\' is appealing for what it will be used for. The one thing I first though of was SomeModule\new_object::test_function();

    Wouldn't it try to evaluate the '\n' as a \n new line? I suppose it will be out of the double quite string scope so it could be alright... could get messy if eval()-ing code, though.

  42. Oblig. Bender by OldManAndTheC++ · · Score: 2, Funny

    Yeah, screw those guys! I'll make my own PHP -- with blackjack! and hookers!

    --
    Soylent Green is peoplicious!
  43. Re:WTF? by TLLOTS · · Score: 2, Interesting

    Not at all, there were some serious ambiguity issues that needed to be resolved.

    Take the following code:

    ----------

    # first file

    namespace Foo;

    function blarg()
    {
          echo "function";
    }

    # second file

    class Foo {
            public static function blarg()
            {
                    echo "method";
            }
    }

    # third file

    Foo::blarg(); // what does this output?

    -------

    The problem here is that calling a static method and calling a function within a namespace share the exact same syntax, so at a glance you can't be sure what will happen.

    If we assume that PHP internally does its lookups in these situations as function first, then class, then there's four possible scenario's in this situation.

    1. You have both files included at once, PHP gives a fatal error due to the ambiguity.

    2. You only have the first file (namespaced function) included, so it outputs "function".

    3. You only have the second file (static class) included, so it outputs "method".

    4. You have neither files included, but you have defined an autoload method which loads your static class file and outputs "method".

    Obviously the ambiguity is a serious issue, so you need to resolve it somehow. Either you make a special syntax for calling functions in namespaces, you change namespaces so they can only be used for classes, or you change the seperator for namespaces to something else.

  44. Forty years down the road by Master+of+Transhuman · · Score: 2, Insightful

    with 4GB RAM machines with TB hard drives - and we're still worrying about "the number of characters".

    Oh, please. Fucking nerds.

    For the last forty years, we've been constrained by one pointless limitation after another, not to mention the complete inability of a PC to discern what is an identifier and what is command syntax if it has fucking SPACES in it.

    Get your heads out of your asses.

    And learn to type.

    "Number of characters" - Jesus Baron von Christ!

    --
    Richard Steven Hack - This sig is TOO GODDAMN SHORT TO DO ANYTHING USEFUL WITH! MORONS!
  45. And just to add to that by Master+of+Transhuman · · Score: 2, Informative

    calling a computer programmer a "software engineer" is like calling a crack whore a "courtesan".

    There's no "engineering" involved for ninety nine percent of them.

    --
    Richard Steven Hack - This sig is TOO GODDAMN SHORT TO DO ANYTHING USEFUL WITH! MORONS!
  46. Re:Well now we all know what trouble this is going by glwtta · · Score: 2, Insightful

    Yeah, and if you are running PHP on a Windows server, do you really need any more trouble?

    --
    sic transit gloria mundi
  47. Re:That's because.. by retiman · · Score: 2, Interesting

    I don't know what you mean by "weakly typed language" as it has several different meanings*, but I think being or not being weakly typed doesn't have anything to do with it.

    The fact is that PHP automatically and forcefully converts operands into the correct type with the '+' operator (is this what you mean by weakly typed?). That is, "5" + 5 = 10, so all operands are converted to numerics.

    Incidentally, Java, will do this the other way, as "5" + 5 = "55". All operands to + get converted to String ("5" + obj is the same as "5" + obj.toString). Curiously, nobody is quick to call Java a weakly typed language.

    The exception, in Java's case, is the rule that + will always concatenate:

    5 + "5" = 55 // Java
    "5" + 5 = 55 // Java
    5 + 5 + 5 + "5" = 155 // Java

    Any time a String is encountered, Java will decide it is a concatenation operation (never addition). If you want to use the + operator for addition, you'll have to make sure all the operands are of some numeric type.

    For PHP, the original developers decided that it would be much more useful to always be able to add instead of concatenate. For example:

    "b" + 5 = 5 // PHP; b gets converted to numeric value of 0

    Of course, they could have the opposite rule so that if a numeric is present, then you must add; otherwise the operation is a concatenation. My opinion (and theirs probably) is that this rule would be terribly confusing, so they used the . operator for concatenation.

    On the flip side, my opinion is also that having "b" + 5 evaluate to 5 is also terribly confusing! There was nothing stopping them from making PHP behave like Java in this case (and still have PHP be "weakly typed", whatever that means).

    Unfortunately, it's way too late now, as there is already a ton of code exploiting this messy design decision.

    * Some people take weakly typed to mean types are associated with values instead of variables, for example.

  48. Re:It's all a joke by ESqVIP · · Score: 2, Informative
    I don't like to make assumptions about others, but you seem to believe that the majority speaks exclusively English.

    Yes but we are talking about a very, very slim minority here are we not? No offense intended but it seems like your whole point is hinging on the absolute minority of people out there. I can't think of any systems off hand that do this

    According to Wikipedia, the circumflex accent is "used in written Croatian, Esperanto, French, Frisian, Norwegian, Romanian, Slovak, Vietnamese, Romanized Japanese, Romanized Persian, Welsh, Portuguese, Italian, Afrikaans, Turkish and other languages".

    I don't know the keyboard layouts used by all of them, but I'd bet most (if not all) of them use a dead key for both the caret and the circumflex rather than including additional keys, and Portuguese and French have a reasonable number of speakers. Plus there are those who, despite not speaking one of these languages, still have dead keys (for example on US-International). What's the layout used by the people who speak Spanish in the US? If it's US-International, that should be a sizable part of the population even in an English-speaking country.

    So spend the $5 and get a new keyboard?

    Um, no, not always possible. I know this comment went more into my particular problems, but still I saw similar complaints on Reddit. I guess people in other countries also have the same issues of every now and then having to deal with other layouts.

  49. Re:It's all a joke by Requiem18th · · Score: 5, Informative

    And this is (one of) the many reasons PHP sucks:

    Java:
    Attribute/Method access: foo.bar
    Static method access:    Foo.bar
    Package access:          foo.bar.baz

    C#:
    Attribute/Method access: foo.bar
    Static method access:    Foo.bar
    Namespace access:        foo.bar.baz

    Python:
    Attribute/Method access: foo.bar
    Static method access:    Foo.bar
    Module access:           foo.bar.baz

    PHP:
    Attribute/Method access: $foo->bar
    Static method access:    Foo::bar
    Namespace access:        foo\bar\baz

    --
    But... the future refused to change.
  50. Wonderful analogy! by MarkusQ · · Score: 3, Interesting

    GOTO is what your CPU is actually doing 80% of the time.

    And your car's engine spends all of its time repeatedly causing small explosions with volatile petroleum.

    The driver is generally recommended to let the engine do this and not try to intervene or do it themselves.

    Spot on. Dead on target and a car analogy. You rock.

    --MarkusQ

  51. Re:PHP sucks, but it has a very important niche by alien_life_form · · Score: 2, Funny

    In fact, not to start a language war, I think his language of choice should be Perl.

    Cheers,
    alf

  52. Re:It's all a joke by Haeleth · · Score: 4, Insightful

    So spend the $5 and get a new keyboard? Unless your keyboard is physically, permanently attached. Then again we get into the very, very minority.

    "People with laptops" is a very, very tiny minority?