Aymane Shuichi Aymane Shuichi - 6 months ago 14
PHP Question

How does PHP interpret Javascript's Null value?

Sol let's suppose that we send a post query to a PHP file,
this query where we have ...&title=title
where title is for example

title=$(#title).val();
(assuming we're including Jquery)
in PHP we have
$title=$_POST['title'];

Let's suppose then that title is null , will PHP consider null as string ? or something empty ?

Answer

From the PHP Manual:

The special NULL value represents a variable with no value. NULL is the only possible value of type NULL.

A variable is considered to be NULL if:

  • it has been assigned the constant NULL.
  • it has not been set to any value yet.
  • it has been unset().

"NULL" is not the same as NULL.

var_dump("null" == NULL);

Outputs:

bool(false)