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