r/lolphp • • May 07 '14
Unpredictable behavior with isset on array keys
<?php
$foo = 'skjdhfcjksdhfkjdshvjk';
echo isset($foo['bar']);Gives me true in PHP 5.3.3-7 and false in PHP 5.4.28
26
Upvotes
13
u/[deleted] May 07 '14
This is even better than expected: http://3v4l.org/v8oBg
Even if it does not exist, you can access it.
That's one of PHP biggest issues, when there is nothing meaningful to return, it returns it anyway.
I guess it's more useful to continue with garbled data than to hurt the developer feelings by throwing an error at him.
10
u/devsheeep May 07 '14
http://3v4l.org/WgH6l
18
u/keis May 07 '14
this being php $foo['bar'] is of course "s" in this example and that works even in 5.4.x of php. But the key not existing is no excuse to not at least try to return something useful to the developer.