ID:               36019
 Updated by:       [EMAIL PROTECTED]
 Reported By:      zola at zolaweb dot com
-Status:           Feedback
+Status:           Bogus
 Bug Type:         Unknown/Other Function
 Operating System: Windows
 PHP Version:      4.4.2
 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------

[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

Reply via email to