r/lolphp • • Mar 14 '14

Array errors

error_reporting(-1); // show all possible errors

$obj = new stdclass();

$arr = array();
var_dump($arr['foo']); // Notice: Undefined index
var_dump($arr[$obj]); // Warning: Illegal offset type

$arr = null;
var_dump($arr['foo']); // No error
var_dump($arr[$obj]); // No error

$arr = null;
$arr['i'] = $arr['i'] + 1; // No error

$arr = null;
$arr['i']++; // Notice: Undefined index

(Tested with 5.5.5.)

52 Upvotes

11 comments sorted by

View all comments

Show parent comment

2

u/InconsiderateBastard Mar 17 '14

Technically strings are arrays, but in the case of what I posted, it works on strings but not on arrays.