PHP 4.0 Bug #7387 Updated: weird problems with unquoted array subscripts
| From: | lyric@php.net | Date: | Sun, 22 Oct 2000 14:57:47 +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-35776@lists.php.net to get a copy of this message | ||
ID: 7387
Updated by: lyric
Reported By: delme@jumeaux.bc.ca
Status: Analyzed
Bug Type: Scripting Engine problem
Assigned To:
Comments:
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;
Previous Comments:
---------------------------------------------------------------------------
[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