#34772 [Bgs]: Weird type juggling problem (may not be a bug at all)
| From: | rn214 at cam dot ac dot uk | Date: | Fri, 07 Oct 2005 13:13:05 +0000 |
| Subject: | #34772 [Bgs]: Weird type juggling problem (may not be a bug at all) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-86191@lists.php.net to get a copy of this message | ||
ID: 34772
User updated by: rn214 at cam dot ac dot uk
Reported By: rn214 at cam dot ac dot uk
Status: Bogus
Bug Type: *General Issues
Operating System: Linux
PHP Version: 4.4.0
New Comment:
Sorry to trouble you. The behaviour does seem wrong to me, so I thought
it was better to report it as a possible bug than to ignore it.
Previous Comments:
------------------------------------------------------------------------
[2005-10-07 09:36:37] sniper@php.net
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions. Due to the volume
of reports we can not explain in detail here why your report is not
a bug. The support channels will be able to provide an explanation
for you.
Thank you for your interest in PHP.
Try var_dump() on it..
------------------------------------------------------------------------
[2005-10-07 06:37:17] rn214 at cam dot ac dot uk
Description:
------------
Something rather weird happens when you define a variable first as a
string and then as an array. I am not sure whether this is actually a
bug, or my failure to understand null-terminated strings. However, the
effect is that the empty-string '' is evaluated as true. Sorry for
wasting your time if this is spurious.
Reproduce code:
---------------
$foo[1]="x";
$foo=$foo[1];
$foo[2]='';
if ($foo[1]){
echo "foo 1 is '$foo[1]' and is true<br>";
}
if ($foo[2]){
#The value of $foo[2] printed here is \0. It evalutes as true, and is
a 1-character length string.
#This is DESPITE that fact that I just set it to be empty!
echo "foo 2 is '$foo[2]' and is true<br>";
}
#A simpler case:
$bar="x";
$bar[2]='';
echo "bar 2 is '$bar[2]'<br>";
Expected result:
----------------
Not quite sure what to expect. But I do not expect the value of foo[2]
which I just set to the empty string to evaluate as true!
I would expect only to see one line:
bar is ''
Actual result:
--------------
foo 1 is ' ' and is true
foo 2 is 'N' and is true
bar is 'N'
(I have used the character N to represent NUL, since
it would otherwise be invisible. Also note the space between
the quotes in the first line)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=34772&edit=1