Logic bug in php 5.3

So… here we go again. After the ugly php 5.2 output buffer crashes, we now have the php 5.3 logic bugs:

$foo = 0;
var_dump('foo' == $foo); // true
var_dump($foo == 'foo'); // true
var_dump('foo' === $foo); // false
var_dump($foo === 'foo'); // false

If your scripts are returning completely unexplainable results on php 5.3 platforms, that’s one possibility to keep in mind. I initially found it while looking into memcached-related problems.

The worst part of it, though, is that it’s not a bug: it’s a feature.

Comments on Logic bug in php 5.3 Leave a Comment

    • You’re totally right, yeah. Further investigation revealed it wasn’t new at all.

      What had confused me into thinking it was, is that I had never run into the issue before, and there is an implicit string to number conversion when comparing numerical strings:

      var_dump(0 == ‘0’); // true
      var_dump(1 == ‘1’); // true
      var_dump(1 == ‘2’); // false

      You learn stuff everyday, as they say. Even when you’re a php junkie. :-D

  1. Adding to the previous comment, and further adding to the confusion, php has this obnoxious feature:

    var_dump(” == ‘0’); // true, because both are empty
    var_dump(” === ‘0’); // false

  2. This is why you have to kick and scream in situations like Ticket #7748. Data types are twice as important in languages that don’t enforce them.

Leave a Comment

The images that show near comments are Gravatars.

Support requests should be supported through the Support Page. Thank you.

Fields marked by an asterisk (*) are required.