A PHP variable has a value and a type. In most practice cases we consider only about the value of the variable. But there may be times we have to consider the type of the variable as well.

For an example value NULL (or 0 or whatever of following you likeĀ  to call it) can be assigned to a variable with different types like this.

$x = NULL; NULL data type. Yea it is the real NULL.
$x = 0; Integer data type.
$x = 0.0; Float data type.
$x = FALSE; Boolean data type.
$x = “”; String data type.

You can check the operator ‘===’ (triple equal operator) to check equality of both their values and types simultaneously.

You can have a good idea about this by looking at the following piece of code.

// lets check the equality of NULL and 0 with
// double equal operator
if(NULL == 0) {
	echo "NULL == 0 is TRUE</br>";
}
else {
	echo "NULL == 0 is FALSE</br>";
}

// now lets check the equality of NULL and 0 with
// triple equal operator
if(NULL === 0) {
	echo "NULL === 0 is TRUE</br>";
}
else {
	echo "NULL === 0 is FALSE</br>";
}

This will eventually print the following result.

NULL == 0 is TRUE
NULL === 0 is FALSE

PHP variables including class variables get the NULL value and NULL type by default. So if no one assign them a value it remains NULL.

So in a case you have to check for unused variables (or for “NULL”-ness of a variable) you should always use the triple equal operator (===) with NULL token. Otherwise you may mistakenly treat not NULL things like ‘0′ or empty string (”") as null that may have been valid data for your application.