Basic tech stuff

Programming and Linux administration

Archive for the ‘php’ Category

PHP is seriously sick

Posted by Daniel Brahneborg on 2007 March 21

It’s obvious that ‘true‘ should be considered true and ‘false‘ should be considered false in an if statement.

It’s sane that ‘1‘ should be true, but slightly annoying sometimes that ‘0‘ is false. Especially since '0==null‘ also evaluates to true. What idiot decided that?

Then it gets worse. The expression ‘array()‘ is also false, making it impossible to use “if ($variable)” to decide if the variable has been set to anything.

On top of that, ‘array()==null‘ also evaluates to true. WTF? Seriously?

After some searching, my little if statement now looks like this: “if (is_array($variable)) …”. Gee, thanks.

When coming from an object oriented world, an object is an object, and an explicitly created object is certainly different from null. That’s so fundamental it goes beyond saying.

Combined with the fact that a normal variable assignment always (unless you’re using “&=“) makes a deep copy of an array, my little loop to create a nested array of arrays, became a nightmare. It’s three times as long as the Ruby version, and with lots of duplicated code since I always have to populate each array before adding it into the containing object.

And people actually like this language? Why?

Andra bloggar om: , .

(Edit: Corrected the true/false thing found by Svava)

Advertisements

Posted in php, programming | 12 Comments »