PHP Annoyances

Beatnik on 2005-01-22T12:25:44

So I've started reading in this bible of the dark side. After reading a few pages, I already felt the urge rising to make some mental notes.

  • There is a list() function (page 16)
  • Function names in PHP are case INsensitive, variable names are not (page 17)
  • Although semicolons are required at the end of a block, they are not at the end of a ?> section. (page 18)
  • PHP supports both the # type comment as both the C++ style // and the C style /* */. It also has this weird side effect on closing the # type comment on one line. You can do <?php $foo = 4; #Set foo ?> <?php echo $foo?> (page 19-21).
  • Apparently, $| is not a valid variable name. There goes perl compatibility ;) (page 22).
  • Defining constants is done in a very C like way... but not quite. define('FOO',5); (page 23)
  • The list of PHP core language keywords include words like endfor, $this, __sleep, endforeach, __wakeup, endif, old_function and switch. That last one is the worst of all... If I wanted switch, I would have used some perl module :) (page 23)
  • There are function aliasses. is_int() has is_integer(). (page 24)
  • An object with no functions or values is also considered false (page 27)
  • There is an array() function. (page 27)
  • There seems no way (at this part of the book) to distinguish the difference between a scalar and an array. They both use the $ sigil.(page 27)
  • sort() sorts the array by reference, not by value. (page 28)
  • There is more than one sort function. (page 28)



  • But...


  • Cool is that they have the foreach($foo as $bar => $list) { echo $bar; } which will be in Perl 6. (page 27)

  • I'm about one third through chapter two.. I predict some more annoyances pretty soon.


    That's not all...

    bart on 2005-01-22T14:01:23

    Yes there are more annoyances. From the top of my head:
    • Very inconsequent in naming the built-in functions. Sometimes, there's underscores between the word parts, sometimes they're just concatenated. There's no fixed rules for the word part orders. Sometimes, related/similar functions have vastly different names: strtolower(), strtoupper(), ucfirst(), ucwords(), mb_strtolower().
    • Some keywords require parens, while others can do without: for example:
      echo "foo";
      works without problem, but you do need the parens in
      die("foo");
    • and the well know age old "there's no variable scoping, apart from function level scoping" complaint. If only file-level scoping was supported, I'd already be a much happier man. Now, if you do
      foreach($array as $id) {
          ...
      }
      at the top level, your global $id will have been cluttered.
    And there's zillions more...
    There seems no way (at this part of the book) to distinguish the difference between a scalar and an array. They both use the $ sigil.(page 27)
    You should think of it as the array and the array ref being equivalent. You cant have both a $foo and a @foo as both are the same variable: $foo.

    In addition, treating a string as an array results in characters being picked out of the string, like Perl's substr. Well, almost:

    $x = "foobar";
    $x[3] = "XYZ";
    echo $x;
    prints "fooXar".
    There is an array() function. (page 27)
    Yes, and there's no "[ ... ]" shortcut, like in Javascript. (And in Perl.)
    There is more than one sort function. (page 28)
    Yes, and the array_multisort() is nothing short of a nightmare. The API is very difficult, every column is a separate array, and there's no way to have it sort on a variable number of columns. Just give me the unified and very powerful sort BLOCK LIST from Perl, any day.

    Re:That's not all...

    Beatnik on 2005-01-22T14:30:51

    I'll probably get those all of those items on my next few chapters. Only made it to page 29 so far :)