Top 10 12 Reasons why Javascript is Better than PHP

  1. Functions that return objects can be treated like objects. document.getElementsByTagName('ul')[0].innerHMTL works the same as var ul=document.getElementsByTagName('ul'); ul=ul[0]; ul.innerHTML;. But, for some silly reason, $xml->xpath('//ul')[0]->asXml() throws a bunch of errors.
  2. Dots are prettier than arrows.
  3. It runs on someone else’s machine.
  4. It has a lisp. (All Hail the Mighty λ!)
  5. Only functions cause scope. (Oh, the hours tracking down an elusive bug that happened because the scope created by a switch statement in a php file caused one variable to be updated, but not another.)
  6. You can do it in the browser.
  7. You can do it inline
  8. There aren’t a bajillion functions, and you can enumerate them easily.
  9. Firebug
  10. Prototype Chains

Some more that I forgot about:

  1. Logical ANDs and ORs can be used for variable assignment.
    function myFn(a) { a = a || 'default value'; };
  2. No dollar signs!! (unless you want them)

2 Responses to “Top 10 12 Reasons why Javascript is Better than PHP”

  1. On August 28th, 2006 at 06:18:26, mattbta Said:

    All hail firebug. That has been so instrumental in debugging AJAX stuff I’ve been working on. I used to hate javascript but have warmed up to it as it is so easy to manipulate the dom.

    Good post.

  2. On January 31st, 2007 at 20:50:45, Peter Goodman Said:

    PHP5 allows a function to return an object and have it accessed as well, e.g.:
    function moo() {
    return new Whatever;
    echo moo()->someFunc();

    The same cannot be done (to my knowledge) with accessing array elements right after calling the function, (moo()[0]…); however, the PHP5 SPL ArrayAccess class should be tested to see if it would in fact work. (where Whatever would implement ArrayAccess)

Leave a Reply

Comments are moderated like crazy using a variety of plugins. There is a very high likelihood that your comment won't show up right away, especially if you have never commented here before, but it was not deleted.

Please be patient, and do not post your comment more than once. It will show up once it is approved.

You must be logged in to post a comment.