note 97612 deleted from function.property-exists by degeberg

From: Date: Wed, 28 Apr 2010 09:08:20 +0000
Subject: note 97612 deleted from function.property-exists by degeberg
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-168748@lists.php.net to get a copy of this message
Note Submitter: henry at weismannweb dot com ---- Here is a function to check if multiple properties exist: <?php /** * This function checks if the given properties exists in the specified object. * * @param object * @param array * @return bool */ function properties_exist($object, $properties) { if(!is_object($object) || empty($properties)) { return FALSE; } foreach($properties as $property) { if(!property_exists($object, $property)) { return FALSE; } } return TRUE; } $object = new Class(); $properties = array('foo','bar'); properties_exist($object, $properties); You could further build this up to accept the array or a string containing a single property to check....probably would be nice if this core php function accepted an array of properties. ?>

« previous php.notes (#168748) next »