How to check empty object in php?
In this post we will show you how to check empty object in PHP.
1. Code:
<?php function isCheckEmptyObject($obj){ foreach (get_object_vars($obj) as $srcKey => $srcValue) { if (null != $srcValue) { return false; } } return true; } class Soltuts{ public $id; public $name; public $description; } $sol = new Soltuts(); $sol->id = 1; $sol->name = "String"; var_dump(isCheckEmptyObject($sol)); ?>
2. Example:
Input:
Object: Soltuts(id= 1, name= "String");
Output:
output: false;