PHP 4.0 Bug #7387 Updated: weird problems with unquoted array subscripts

From: Date: Sun, 22 Oct 2000 19:10:31 +0000
Subject: PHP 4.0 Bug #7387 Updated: weird problems with unquoted array subscripts
Groups: php.dev 
Request: Send a blank email to php-dev+get-35810@lists.php.net to get a copy of this message
ID: 7387 Updated by: stas Reported By: delme@jumeaux.bc.ca Status: Analyzed Bug Type: Documentation problem Assigned To: Comments: moving to doc's problem, since it's clearly not engine bug but doc issue. Previous Comments: --------------------------------------------------------------------------- [2000-10-22 14:52:00] delme@jumeaux.bc.ca i must ask, then - why has the bareword `null' suddenly picked up a special meaning to the scripting engine? this seems like a *bad* design move to me, since it means that this bareword suddenly behaves differently than before. it's also not consistent - *are* there other barewords that have special meanings in similar contexts? also, it's not mentioned at http://www.php.net/version4/incompatibilities.php. this is a little dangerous. if we maybe introduced a null() *function* i could see it... --------------------------------------------------------------------------- [2000-10-22 10:57:47] lyric@php.net Two distinct issues: a) The problem starts with the fact that >>null<<, in all it's forms, is a magic word with a single unique value. Thus $a[null] is the same variable as $a[Null], but NOT the same as $a["Null"]. The problem is that " $a[null] " is being read as $a["null"] which is probably the best way to handle this single ambigious case. SOLUTION: don't use NULL as an array index without quoting it. b) the difference is simply in the way a boolean is printed to the screen. A true is now displayed as '1', a false is now '' (the empty string). I'm not sure why that was changed. SOLUTION: echo ($cond)?1:0; --------------------------------------------------------------------------- [2000-10-21 23:32:40] delme@jumeaux.bc.ca I think it's better simply to demonstrate this bug or bugs than to try and explain it. given this code: <? $test[Null]='a test with capitals'; $test[null]='a test with all lower case'; $empty[Null]=''; $filled[Null]='test'; print "$test[Null] = '"; print $test[Null]; print "'<BR>$test[Null] (interpolated) = '$test[Null]'<BR>"; print "$test[null] = '"; print $test[null]; print "'<BR>$test[null] (interpolated) = '$test[null]'<BR>"; print "!$math[Null] = '"; print !$empty[Null]; print "'<BR>!$filled[Null] = '"; print !$filled[Null]; print "'<BR>"; ?> under php3 i got what i would expect: $test[Null] = 'a test with capitals' $test[Null] (interpolated) = 'a test with capitals' $test[null] = 'a test with all lower case' $test[null] (interpolated) = 'a test with all lower case' !$math[Null] = '1' !$filled[Null] = '0' but under 4.0.3pl1 (and 4.0.1pl2) i get: $test[Null] = 'a test with all lower case' $test[Null] (interpolated) = '' $test[null] = 'a test with all lower case' $test[null] (interpolated) = '' !$math[Null] = '1' !$filled[Null] = '' something is very wrong. --------------------------------------------------------------------------- Full Bug description available at: http://bugs.php.net/?id=7387

« previous php.dev (#35810) next »