See the documentation .
This is a null:
$valor = null;
This is an empty string , nothing null:
$valor = "";
So it compares null, but an empty string is considered null as well, it's a complete non-sense , but PHP looks like this:
if($valor == null){}
This checks to see if it is empty string :
if($valor == "") {}
It is often considered a better way to buy, but in this case it makes no real difference:
if($valor === null) {}
You can also do:
if (is_null($valor)) {}
Documentation .
Or:
if (empty($valor)) {}
Documentation .
You'll find a difference in cases like this:
$a = array();
echo $a == null; //true
echo $a === null; //false
It's so confusing, that I would avoid using nulls in PHP.
empty is_null
==null ===null isset array_key_exists
ϕ | T | T | F | F
null | T | T | F | T
"" | T | F | T | T
[] | T | F | T | T
0 | T | F | T | T
false | T | F | T | T
true | F | F | T | T
1 | F | F | T | T
$valor = null;
| F | F | T | T
Table taken from OS response .
At least in "normal" languages it looks like this: