Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between NULL and null in PHP

Tags:

php

null

Is there a difference between NULL and null in PHP? Sometimes they seem to be interchangeable and sometimes not.

edit: for some reason when I read the documentation linked to in the answer (before posting this question) I read it as "case sensitive" instead of "case insensitive" which was the whole reason I posted this question in the first place...

like image 700
cmcculloh Avatar asked Aug 12 '08 14:08

cmcculloh


People also ask

What is the difference between null and null in PHP?

Null is case insensitive. From the documentation: There is only one value of type null, and that is the case-insensitive keyword NULL. Unless an exact match in DB is queried.

What is the difference between null and null?

@arvin_codeHunk, null is an empty object, whereas "null" is an actual string containing the characters 'n', 'u', 'l', and 'l'. The String here is written as null telling you that you just took the String value of null which is equal to "null" . So a null will not be equal to "null" literal. @arvin_codeHunk..

Is null null PHP?

$x === nullNull is a special data type in PHP which can have only one value that is NULL. A variable of data type NULL is a variable that has no value assigned to it. Any variable can be empty by setting the value NULL to the variable.

What is the null in PHP?

In PHP, a variable with no value is said to be of null data type. Such a variable has a value defined as NULL. A variable can be explicitly assigned NULL or its value been set to null by using unset() function.


3 Answers

Null is case insensitive.

From the documentation:

There is only one value of type null, and that is the case-insensitive keyword NULL.

like image 77
mbillard Avatar answered Oct 18 '22 01:10

mbillard


There is no difference. Same type just its a case insensitive keyword. Same as True/False etc...

like image 28
Desolator Avatar answered Oct 18 '22 00:10

Desolator


Either will work. But the official PHP style guide, PSR-12, recommends lowercase.

https://www.php-fig.org/psr/psr-12/, Section 2.5

like image 2
RedDragonWebDesign Avatar answered Oct 18 '22 00:10

RedDragonWebDesign