cmcculloh
cmcculloh

Reputation: 48603

Difference between NULL and null in PHP

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...

Upvotes: 107

Views: 40951

Answers (4)

Stack Overflow
Stack Overflow

Reputation: 2968

NULL = null, which means null = NULL, both refer to each other and have only one data type null.

PHP Manual:

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

The consideration should be only taken when the underlying Database has specific requirements.

But if we take the example of MySQL DBMS, the null value in the column is represented as uppercase NULL, but both cases will work. For your satisfaction, you can use NULL for example.

Upvotes: 0

RedDragonWebDesign
RedDragonWebDesign

Reputation: 2571

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

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

Upvotes: 7

Desolator
Desolator

Reputation: 22759

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

Upvotes: 12

mbillard
mbillard

Reputation: 38842

Null is case insensitive.

From the documentation:

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

Upvotes: 141

Related Questions