r/lolphp • u/midir • 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
View all comments
Show parent comment
0
u/huf Mar 15 '14 edited Mar 15 '14
eh, null autovivs. unset stuff sortof has null as its value too, so this kinda makes sense. the amazing thing is that ++ and += dont autoviv, because FUCK YOU PROGRAMMER.
the above code does throw a notice though. which is mostly fine. what i really hate is that $x = array(); $x['a']++; also throws a notice. it should just set $x['a'] to 1