24 Jan 2010 00:01
Patch for PHP bug: accessing elements in objects cast to arrays
Tommy Montgomery <t.montg <at> gmail.com>
2010-01-23 23:01:06 GMT
2010-01-23 23:01:06 GMT
I wrote a patch for PHPUnit for the (known) PHP bug outlined here: http://bugs.php.net/bug.php?id=46758. Basically, if you have an object with numeric properties and then cast to an array, accessing those properties is difficult and buggy. Here's an example script that illustrates this: $foo = new stdClass(); $foo->{0} = 'foo'; $a = (array)$foo; var_dump($a, key($a), array_key_exists('0', $a), array_key_exists(key($a), $a)); This will output array(1) { ["0"]=> string(3) "foo" } string(1) "0" bool(false) bool(false) Anyway, I wrote a patch for the IsEqual constraint to handle these weird situations, but I noticed that PHPUnit is now on Git rather than SVN, and I don't really want to spend a couple hours right now learning Git, so I thought I'd just send the patch here. The patch is attached and is for PHPUnit 3.4.9. Thanks, Tommy(Continue reading)
RSS Feed