From: nicolasconnault Date: Fri, 27 Apr 2007 03:54:53 +0000 (+0000) Subject: MDL-9506 Added a function that checks an object for the definition of a given variabl... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=1f3f3629a4a2ceb9644d1f0572adcb70421447a1;p=moodle.git MDL-9506 Added a function that checks an object for the definition of a given variable. Similar to in_array(). --- diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 0a98799af5..72a5f09393 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -7067,5 +7067,19 @@ function is_newnav($navigation) { } } +/** + * Checks whether the given variable name is defined as a variable within the given object. + * @note This will NOT work with stdClass objects, which have no class variables. + * @param string $var The variable name + * @param object $object The object to check + * @return boolean + */ +function in_object_vars($var, $object) +{ + $class_vars = get_class_vars(get_class($object)); + $class_vars = array_keys($class_vars); + return in_array($var, $class_vars); +} + // vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140: ?>