#34772 [Bgs]: Weird type juggling problem (may not be a bug at all)

2005-10-07 Thread rn214 at cam dot ac dot uk
 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] [EMAIL PROTECTED]

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 truebr;
}

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 truebr;
}


#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=34772edit=1


#34772 [NEW]: Weird type juggling problem (may not be a bug at all)

2005-10-06 Thread rn214 at cam dot ac dot uk
From: rn214 at cam dot ac dot uk
Operating system: Linux
PHP version:  4.4.0
PHP Bug Type: *General Issues
Bug description:  Weird type juggling problem (may not be a bug at all)

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 truebr;
}

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 truebr;
}


#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 bug report at http://bugs.php.net/?id=34772edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=34772r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=34772r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=34772r=trysnapshot51
Fixed in CVS:http://bugs.php.net/fix.php?id=34772r=fixedcvs
Fixed in release:http://bugs.php.net/fix.php?id=34772r=alreadyfixed
Need backtrace:  http://bugs.php.net/fix.php?id=34772r=needtrace
Need Reproduce Script:   http://bugs.php.net/fix.php?id=34772r=needscript
Try newer version:   http://bugs.php.net/fix.php?id=34772r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=34772r=support
Expected behavior:   http://bugs.php.net/fix.php?id=34772r=notwrong
Not enough info: 
http://bugs.php.net/fix.php?id=34772r=notenoughinfo
Submitted twice: 
http://bugs.php.net/fix.php?id=34772r=submittedtwice
register_globals:http://bugs.php.net/fix.php?id=34772r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=34772r=php3
Daylight Savings:http://bugs.php.net/fix.php?id=34772r=dst
IIS Stability:   http://bugs.php.net/fix.php?id=34772r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=34772r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=34772r=float
No Zend Extensions:  http://bugs.php.net/fix.php?id=34772r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=34772r=mysqlcfg