Reputation: 92
$view = new UserView();
var_dump(is_null($view))
echo '<br>';
var_dump($view);
bool(false)
object(UserView)#2 (0) { }
How is this even possible? And how I check if the object is not null?
Upvotes: 0
Views: 76
Reputation: 22
Try the function get_object_vars https://secure.php.net/manual/en/function.get-object-vars.php
array get_object_vars ( object $object ) Gets the accessible non-static properties of the given object according to scope.
$view = new stdclass();
echo count(get_object_vars($view));
Upvotes: 0
Reputation: 10714
Your object is not null, it's just empty, try :
$empty = (bool) count((array) $view);
Upvotes: 1