[ABE.pm] php and me

Ricardo SIGNES perl.abe at rjbs.manxome.org
Mon Aug 11 09:50:23 PDT 2008


I am porting Rx to PHP as part of my "make Rx run everywhere" campaign.

Oh, how PHP makes me crazy!  Here is the spin of the century:

  The array type in PHP is very versatile.

I particularly like it in reference to:

  // This array is the same as ...
  array(5 => 43, 32, 56, "b" => 12);

  // ...this array
  // array(5 => 43, 6 => 32, 7 => 56, "b" => 12);

Oof!  I also found this gem while looking up return.

  Note:  Note that since return() is a language construct and not a function,
  the parentheses surrounding its arguments are not required. It is common to
  leave them out, and you actually should do so as PHP has less work to do in
  this case.  

So, first of all, you want me to optimize for the language?  Really?  Isn't it
there to make my life easier?

Well, that's not the only reason:

  Note:  You should never use parentheses around your return variable when
  returning by reference, as this will not work. You can only return variables
  by reference, not the result of a statement. If you use return ($a); then
  you're not returning a variable, but the result of the expression ($a)
  (which is, of course, the value of $a). 

Yow.  Then there's http://www.php.net/quickref.php

Anyway, maybe I shouldn't act like such a language basher, since I'm probably
going to ask some stupid PHP questions over the next day or two.  Mostly about
objects and arrays.

I knew that arrays had multiple-personality disorder, but it seems even wackier
than I thought.  I have a sinking feeling that validing that something is a
sequence (which means something like "an ordered list of values") or a record
(which is something like "a group of named values") is going to be hard to get
just right.  I think I will need to allow arrays for both and also stdClass
objects for records.

I really like the library-building culture of the other dynamic languages.
The language stays small and is thus easy to learn.  PHP isn't without
libraries, especially now that there are tolerable classes, but... oof.  I wish
they'd gone that way much earlier.

-- 
rjbs


More information about the ABE-pm mailing list