note 97612 added to function.property-exists
| From: | henry at weismannweb dot com | Date: | Wed, 28 Apr 2010 08:55:29 +0000 |
| Subject: | note 97612 added to function.property-exists | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-168746@lists.php.net to get a copy of this message | ||
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.
?>
----
Server IP: 208.69.120.55
Probable Submitter: 74.76.190.36
----
Manual Page -- http://www.php.net/manual/en/function.property-exists.php
Edit -- https://master.php.net/note/edit/97612
Del: integrated -- https://master.php.net/note/delete/97612/integrated
Del: useless -- https://master.php.net/note/delete/97612/useless
Del: bad code -- https://master.php.net/note/delete/97612/bad+code
Del: spam -- https://master.php.net/note/delete/97612/spam
Del: non-english -- https://master.php.net/note/delete/97612/non-english
Del: in docs -- https://master.php.net/note/delete/97612/in+docs
Del: other reasons-- https://master.php.net/note/delete/97612
Reject -- https://master.php.net/note/reject/97612
Search -- https://master.php.net/manage/user-notes.php