tags:

views:

1046

answers:

2

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

+15  A: 

Null is case insensitive.

From the documentation:

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

GoodEnough
A: 

Usually in programming 'null' is empty varibale of an any type while no memory for it is allocated. In php I gues too.

Foo f; // is null
f = new Foo(); // 'new' is a operator, function for memory allocating

'SQL NULL' is the sutiation when value for a column is not yet assigned. NOT NULL attribute is not set and no default value is provided.

INSERT INTO t(ID,value) VALUES ('{123}', NULL);

In general, this concepts are the same. 'Not yet assisgned value'. But in implementation, 'null' is empty value, but DbNull is special class which represents SQL NULL.

abatishchev
Be careful not to confuse "null" with "empty". $x = array() and $x = '' are both "empty" but they are certainly not "null". Specifically, it is incorrect to say that null is an empty variable of any type. Actually, it is a variable of null type. Any other type of variable can not be null, it can be empty but as it has a type it has been declared with a value and is therefore not null.
Dustin Fineout