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...
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.
@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..
$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.
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.
Null is case insensitive.
From the documentation:
There is only one value of type null, and that is the case-insensitive keyword NULL.
There is no difference. Same type just its a case insensitive keyword. Same as True
/False
etc...
Either will work. But the official PHP style guide, PSR-12, recommends lowercase.
https://www.php-fig.org/psr/psr-12/, Section 2.5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With