PHP 4.0 Bug #7387 Updated: weird problems with unquoted array subscripts
| From: | delme at jumeaux dot bc dot ca | Date: | Sun, 22 Oct 2000 18:52:00 +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-35806@lists.php.net to get a copy of this message | ||
ID: 7387
User Update by: delme@jumeaux.bc.ca
Status: Analyzed
Bug Type: Scripting Engine problem
Description: weird problems with unquoted array subscripts
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...
Previous Comments:
---------------------------------------------------------------------------
[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