0

This problem is a bit strange. Why is showed "Is not null", if the value sent is null? Any reason for that?

Parametersapplication/x-www-form-urlencoded
lists_owned null
Source
lists_owned=null

<?php
$lists_owned = $_POST['lists_owned'];

var_dump($lists_owned); // string(4) "null"

if(!is_null($_POST['lists_owned'])) {
    echo "Is not null"; I see this echo
}
?>  

thanks

1
  • 1
    Ignacio is right, also, check if $_POST['lists_owned'] is set before accessing it : $lists_owned = isset($_POST['lists_owned']) ? $_POST['lists_owned'] : null; and only use the $lists_owned variable after that, it's useless to set $lists_owned and to never use it. Commented Apr 4, 2012 at 2:31

3 Answers 3

4

"null" is not null. If you want to check for "null" then you should be using equality.

if($_POST['lists_owned'] != 'null') {
Sign up to request clarification or add additional context in comments.

Comments

1

This is because your post value is a string called 'null' and not an actual null value.

Comments

0

Looks like your value is actually the string "null", not the value null. Ie

<?php
$x = "null";
$y = null;
var_dump($x);
var_dump($y);
?>

Output

string(4) "null"
NULL

Comments

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.