ID: 36019 User updated by: zola at zolaweb dot com Reported By: zola at zolaweb dot com -Status: Bogus +Status: Open Bug Type: Unknown/Other Function Operating System: Windows PHP Version: 4.4.2 New Comment:
Actually, that's not it. It SHOULD be treated as a string, but is treated as NULL sometimes, but as a string other times. if you enclose in single quotes or apply any function to it, it's treated as the construct NULL. If you don't enclose, it's treated as a string. The change in behavior in the same circumstance is what I'm calling to your attention. $array['var'] = "NULL"; In this example, it will yield NULL the string. $sql = "INSERT INTO mytable ($ID, ".$array[['var']).",".$array[['othervar']).")"; If you echo the sql statement, you see this: INSERT INTO mytable (ID, NULL, othervar) If you enclose the variable containing the string NULL in single quotes, you get NULL acting as NULL not a string at all: $sql = "INSERT INTO mytable ($ID, '".$array[['var'])."',".$array[['othervar']).")"; INSERT INTO mytable (ID, '', othervar) Putting the variable in a function also makes it act as NULL: $sql = "INSERT INTO mytable ($ID, ".strtoupper($array[['var'])).",".$array[['othervar']).")"; also yields INSERT INTO mytable (ID, '', othervar) Previous Comments: ------------------------------------------------------------------------ [2006-01-15 13:45:30] [EMAIL PROTECTED] Nevermind, your assumption that "NULL" should be treated as NULL is wrong. "NULL" is just a string, while NULL is a special value. No bug here. ------------------------------------------------------------------------ [2006-01-15 13:24:05] [EMAIL PROTECTED] Not enough information was provided for us to be able to handle this bug. Please re-read the instructions at http://bugs.php.net/how-to-report.php If you can provide more information, feel free to add it to this bug and change the status back to "Open". Thank you for your interest in PHP. ------------------------------------------------------------------------ [2006-01-15 07:08:49] zola at zolaweb dot com 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 this bug report at http://bugs.php.net/?id=36019&edit=1