From: zola at zolaweb dot com Operating system: Windows PHP version: 4.4.2 PHP Bug Type: Scripting Engine problem Bug description: handling of the string NULL
Description: ------------ Two issues with NULL, one with setting NULL as a string containing the letters NULL, and, when one has successfully set the variable to the word NULL, it getting interpreted differently depending on whether the value is enclosed in single quotes or not. I do apologize for not being able to check against the latest version, unfortunately it's not possible to get my host to update until they are damn well ready to, but I did not see this issue reported in the bug reports and thus I think it's worth mentioning. Reproduce code: --------------- I had a form that had several values that didn't have to be set. I wanted to use the word "NULL" as a word (as opposed to the NULL constant) to go into the SQL statement when creating a new record. If I do a check based on the variable having no value: if ($array['var'] == "") { $array['var'] = "NULL"; } Then $array['var'] contains the word "NULL" the way I want it to, BUT I have to be careful with the sql statement (more on this in a moment) On the other hand, if I check via !isset() if (!isset($array['var'])) { $array['var'] = "NULL"; } It treats NULL as the constant and unsets the variable. In the SQL, if I am inserting and put it in as is: $sql = "INSERT INTO mytable VALUES(NULL, ".$array['var'] .", ' ".$array['some_other_var'] ." ',)"; the word NULL replaces $array['var'] as it should, but if I enclose the variable in single quotes (because maybe that variable, if it's set, will contain a space) $sql = "INSERT INTO mytable VALUES(NULL, ' ".$array['var'] ." ', ' ".$array['some_other_var'] ." ',)"; again, it treats NULL as the constant NULL instead of the word. Expected result: ---------------- I would expect that if I am using the string NULL, it will not be treated as the constant NULL, or at the least for the behavior to be consistent--that it will ALWAYS treat it as the constant NULL instead of treating it one way when it isn't enclosed and another way when it is. Actual result: -------------- in isset: $array['var'] is not set to anything in the other example $array['var'] contains the word NULL The first sql line resolves to INSERT INTO mytable VALUES(NULL, NULL, 'some_value')"; The second resolves to INSERT INTO mytable VALUES(NULL, '', 'some_value')"; -- Edit bug report at http://bugs.php.net/?id=36019&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=36019&r=trysnapshot44 Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=36019&r=trysnapshot51 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=36019&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=36019&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=36019&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=36019&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=36019&r=needscript Try newer version: http://bugs.php.net/fix.php?id=36019&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=36019&r=support Expected behavior: http://bugs.php.net/fix.php?id=36019&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=36019&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=36019&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=36019&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36019&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=36019&r=dst IIS Stability: http://bugs.php.net/fix.php?id=36019&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=36019&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=36019&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=36019&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=36019&r=mysqlcfg