Difference between NULL and null in PHP
Asked Answered
C

4

106

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

Cockaleekie answered 12/8, 2008 at 14:8 Comment(8)
NULL=null and vice-versa unless an exact match in DB is queried.Katykatya
@FunkFortyNiner there is no DB involved on this question. Question is about the programming language.Carolus
@PabloPazos why are you pinging me after 6 years have gone by? Plus, if you read my comment again, you will see probable relevance. Look at the keyword "unless" which would be a possible truth.Katykatya
@FunkFortyNiner because comment is not accurate, no DB involved here as I said.Carolus
@PabloPazos Where do you pick up 6 year old questions/comments is what puzzles me. In any event, my comment is worthy.Katykatya
@PabloPazos its a bit ridiculous to even make a comment like yours, what he said is completely relevant and helpful. If someone else came along and looked at this whilst having a DB error it would help fast track a solution, those who its not relevant too will simply move on and look at another answer.Halfhardy
@FunkFortyNiner Thanks for your comment, that was exactly what I needed to hear. I was trying to filter out a database value NULL by using isset() which usually returns false for regular nulls, but with the database value I had to use $value === NULL. I don't quite understand how this is possible, but I arrived at this page with this problem.Seger
@PabloPazos the word "unless" provides extra information here. Now, Funky Forty Niner makes a rather invalid comment when he complains about the difference in his post and response. Regardless of the time, had he been wrong he should've been called out on it.Magdalenemagdalenian
H
140

Null is case insensitive.

From the documentation:

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

Homochromatic answered 12/8, 2008 at 14:11 Comment(4)
Unless an exact match in DB is queried.Katykatya
I'm having issue comparing null value getting from Database query. Can you help?Refer
@FunkFortyNiner SQL and PHP are different languages. Their NULL have different behaviors.Laurasia
For those who are now wondering whether it is better to write the keyword in upper or lower case. The PHP-FIG recommends a lowercase notation for this keyword (see php-fig.org/psr/psr-2). I agree with this because there is less confusion with the MySQL keyword of the same name when written this way. But since these are only recommendations (some of them are controversial, e.g. indentation with spaces vs. tabs), you should know them and with this knowledge you can then decide whether to follow them or not if you haven't any guidelines yet.Select
Z
12

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

Zamarripa answered 18/5, 2013 at 22:28 Comment(0)
H
4

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

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

Harsho answered 30/12, 2021 at 16:38 Comment(0)
D
0

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.

Dardar answered 2/6, 2023 at 14:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.