|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-01-15 13:24 UTC] tony2001@php.net
[2006-01-15 13:45 UTC] tony2001@php.net
[2006-01-15 17:21 UTC] zola at zolaweb dot com
[2006-01-15 17:40 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Sat Feb 07 00:00:02 2026 UTC |
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')";