In PHP, to check if a array
is empty we can use the language function (or language constructor) empty
.
So:
$a = array();
$b = array(1, 2);
var_dump(empty($a), empty($b)); // Imprime: bool(true), bool(false)
But the same does not happen with stdClass
.
$a = (object) array();
$b = (object)array('nome' => 'wallace');
$c = new stdClass(); // A mesma coisa que $a
var_dump(empty($a), empty($b), empty($c)); // Imprime: bool(false), bool(false), bool(false)
See in IDEONE
So what is the way to know that a stdClass
object is empty or not in PHP?