Forum Moderators: coopster

Message Too Old, No Replies

Wow, big datatype issue

         

FourDegreez

5:03 pm on Jun 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can't believe this!

I wrote a script to copy data from one table to another, and encountered a problem. In a VARCHAR field, one of the values was 0 (a zero). I'm reading it from the database using PDO. The PDO resultset shows the value to be 0 as it should. But I then store this value in a variable. Example:

$var = $row['column'];

When I echo the $var, it is empty! PHP is taking zero to mean null or false or whatever. It should be the string '0'.

Now... who knows what kind of hidden bugs may be elsewhere in my code because of this.

FourDegreez

5:18 pm on Jun 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nevermind, false alarm! Sorry.

What actually happened was not as simple as my example; I was passing the value to a constructor like this:

__construct($value=FALSE) {
if ($value) $this->myValue = $value;
...
}

When the string 0 was passed, it was actually the if condition that was resolving to false and thus my value was never set. Again, sorry. I fixed it by changing the if condition to if ($value !== FALSE).

[edited by: FourDegreez at 5:19 pm (utc) on June 28, 2008]