If parameters are passed, then isset
will return TRUE
, only if all parameters are set.
An uninitialized variable is equivalent to the PHP NULL
constant. Then the function isset
will return FALSE
.
If you are dealing with object properties and want to "evaluate" the value of NULL
, you can use: property_exists
instead of isset
:
<?php
class minhaClass{
public $mine;
private $xpto;
static protected $teste;
function teste() {
var_dump(property_exists($this, 'xpto')); //true
}
}
var_dump(property_exists('minhaClass', 'mine')); //true
var_dump(property_exists(new minhaClass, 'mine')); //true
var_dump(property_exists('minhaClass', 'xpto')); //true, para PHP 5.3.0
var_dump(property_exists('minhaClass', 'bar')); //false
var_dump(property_exists('minhaClass', 'test')); //true, para PHP 5.3.0
minhaClass::teste();
?>
To complement, see this table below:
F = false
T = true
isset is_null ===null ==null empty
null | F | T | T | T | T |
unset | F | T | T | T | T |
"" | T | F | F | T | T |
[] | T | F | F | T | T |
0 | T | F | F | T | T |
false | T | F | F | T | T |
true | T | F | F | F | F |
1 | T | F | F | F | F |
<?php
class minhaClass{
public $mine;
private $xpto;
static protected $teste;
function teste() {
var_dump(property_exists($this, 'xpto')); //true
}
}
var_dump(property_exists('minhaClass', 'mine')); //true
var_dump(property_exists(new minhaClass, 'mine')); //true
var_dump(property_exists('minhaClass', 'xpto')); //true, para PHP 5.3.0
var_dump(property_exists('minhaClass', 'bar')); //false
var_dump(property_exists('minhaClass', 'test')); //true, para PHP 5.3.0
minhaClass::teste();
?>
| T | F | F | F | F |