0

This could be connected to my previous question, and maybe a duplicate to this.

Well, why value declared as NULL in MySQL database is returned as "" (empty string), in this case all my functions which returns some value dependently on result of evaluation, dont' work.

$var = NULL; // false
$var = ""; // true

Also I'm dumping result of evaluating:

var_dump(isset($var));

I'm using PDO DB driver, PHP 5.4.7 and MySQL 5.5.27.

Is that like behaviour expected or is this some bug? NULL is saved in field as MySQL NULL, not string 'NULL'.

2
  • 2
    I'm pretty sure $var === NULL would work better. Commented Dec 5, 2013 at 16:51
  • Probably it's NULL, do you check this with is_null() or something else? Commented Dec 5, 2013 at 16:51

1 Answer 1

4

You need to use is_null() to see if the value is null. NULL is equal to nothing. Even another NULL.

(Plus in your example you use an assignment operator (=) and not a comparison operator (== or ===) but I am sure that is just a typo in your question).

Sign up to request clarification or add additional context in comments.

2 Comments

See edit. If I use is_null() my code will always evaluate to false, because NULL is converted to empty string "".
Thanks for your effort, stupid me, strip_tags() actually stripped NULL to empty string in my sanitize function. That was last thing I should expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.