PHP sucks dick through a straw

[prev] [thread] [next] [lurker] [Date index for 2007/01/11]

From: Andy Armstrong
Subject: PHP sucks dick through a straw
Date: 15:52 on 11 Jan 2007
Humph. I'm writing PHP (again) today. I'm just doing a bit of munging on
a data structure - basically turning a hash of objects some of which
have another object in the same hash as their parent into a tree
containing the same objects. It'd be trivial in Perl. In PHP it's not
quite so simple. PHP really likes every assignment to be a deep copy. In
mitigation it dangles the carrot of pretending to support references
using the =& assignment operator. Except that:

    "Complex arrays are sometimes rather copied than referenced. Thus
     following example will not work as expected." [1]

     <?php
         $top = array(
             'A' => array(),
             'B' => array(
                 'B_b' => array(),
             ),
         );

         $top['A']['parent'] = &$top;
         $top['B']['parent'] = &$top;
         $top['B']['B_b']['data'] = 'test';
         print_r($top['A']['parent']['B']['B_b']); // array()
     ?>

There's plenty of madness elsewhere on the same page too. In PHP4
something as innocuous as

     $obj = new Object();

actually makes a deep copy of the newly created object! So the idiom
is instead

     $obj =& new Object();

Which is OK once you get used to the ugliness - but

    "Since PHP 5, new return(sic) reference automatically so using =& in
     this context is deprecated and produces E_STRICT level message."

So it's impossible to write code for something as simple as creating a
new object that works right in PHP4 and still works without warnings in
PHP5. Which of course means you give up on using E_STRICT, which means
you don't see all the other shite that's going on - some of which might
actually be informative.

Somebody remind me why do so many people use a language that can't even
get this completely basic stuff right.

[1] http://uk.php.net/manual/en/language.references.whatdo.php

(reposted from london.pm)

--
Andy Armstrong, hexten.net


Generated at 01:01 on 12 Jan 2007 by mariachi 0.52