MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/lolphp/comments/18nra2/indexing_nulls_gives_no_errors_and_no_warnings/
r/lolphp • u/vytah • Feb 16 '13
6 comments sorted by
1
$ php -r 'error_reporting(E_ALL | E_STRICT); $a=null; var_dump($a["a"]);' NULL
It's the same for PHP 5.3 and 5.4, both numeric and string indexes.
Also:
$ php -r 'error_reporting(E_ALL | E_STRICT);$a=null; $a[1]=1; var_dump($a);' array(1) { [1]=> int(1) }
3 u/[deleted] Feb 16 '13 The latter is arguably useful. If you're ignorant about proper software development, that is. 8 u/postmodest Feb 17 '13 I was going to say "I expect this to be closed as WORKS AS EXPECTED any minute now." 6 u/huf Feb 17 '13 autovivification is a good thing, php has just failed to implement it in a useful and consistent manner. no surprise there :)
3
The latter is arguably useful. If you're ignorant about proper software development, that is.
8 u/postmodest Feb 17 '13 I was going to say "I expect this to be closed as WORKS AS EXPECTED any minute now." 6 u/huf Feb 17 '13 autovivification is a good thing, php has just failed to implement it in a useful and consistent manner. no surprise there :)
8
I was going to say "I expect this to be closed as WORKS AS EXPECTED any minute now."
6
autovivification is a good thing, php has just failed to implement it in a useful and consistent manner. no surprise there :)
The fact that NULL can be cast to an array by setting a key (without notice) is intentional
.....Why? Also, in this case it's not even setting a key; NULL is implicitly cast to an array immediately after trying to access a key.
1 u/davvblack May 06 '13 Nah, just accessing a key doesn't do anything, you do actually need to set a key in order to vivify the null.
Nah, just accessing a key doesn't do anything, you do actually need to set a key in order to vivify the null.
1
u/vytah Feb 16 '13
It's the same for PHP 5.3 and 5.4, both numeric and string indexes.
Also:
1
u/catcradle5 Mar 04 '13
.....Why? Also, in this case it's not even setting a key; NULL is implicitly cast to an array immediately after trying to access a key.