Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does PHP interpret Javascript's Null value?

Tags:

javascript

php

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 ?

like image 727
Aymane Shuichi Avatar asked Jul 06 '26 11:07

Aymane Shuichi


2 Answers

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)
like image 56
Amal Murali Avatar answered Jul 08 '26 23:07

Amal Murali


The title gets converted to a string before sending it to the server.

Converting the JS value null to a string results in a string "null". Therefore, PHP will only interpret the variable as a string.

However, I doubt that you will receive a null value from an empty input box. You will get an empty string instead.

like image 42
ComFreek Avatar answered Jul 09 '26 00:07

ComFreek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!