Page 1 of 1

Cannot set variable to non null value

Posted: Fri Oct 15, 2010 10:26 pm
by jcobban
I must be doing something blindingly stupid, but I just cannot see it. No matter what I try the value of one of my variables stubbornly remains null when it should be a string. The following is some debugging code that I inserted right after the first initialization of the vairable because the value of the variable $notes was unexpectedly null, when it should have been a string.

Code: Select all

$notes    = $event->getDesc(); // last line of existing code
if ($notes == null)
{  // this should not occur
    print "<p>\$notes=null</p>"; // report the problem in the web page
    $notes	= ""; // force the value to a zero-length string
    if ($notes == null) // check that the force worked
        print "<p>\$notes still null</p>"; // but it didn't because I see this second message!
} // this should not occur
I tried changing the name of the variable in case there was something sensitive to that, but nothing worked.

Re: Cannot set variable to non null value

Posted: Fri Oct 15, 2010 11:38 pm
by requinix
Type comparison tables

== does a loose comparison, and with that an empty string and null are equivalent.
=== does a strict comparison, and with that an empty string and null are not equivalent.

Re: Cannot set variable to non null value

Posted: Sat Oct 16, 2010 12:52 am
by jcobban
Thanks. That was the problem.