I use this to check if an object has properties,
function objectHasProperty($input){
return (is_object($input) && (count(get_object_vars($input)) > 0)) ? true : false;
}
But then I want to check further to make sure all properties have values, for instance,
stdClass Object
(
[package] =>
[structure] =>
[app] =>
[style] =>
[js] =>
)
Then I want to return false
if all the properties have empty values. Is it possible? Any hint and ideas?
There are several ways of doing this, all the way up to using PHP's reflection API, but to simply check if all public properties of an object are empty, you could do this:
$properties = array_filter(get_object_vars($object));
return !empty($properties);
(The temporary variable $properties
is required because you're using PHP 5.4.)