Object can use foreach in PHP 5

pull/11/head
Mike Cao 14 years ago
parent ce8dbfc435
commit 540f7ae44f

@ -198,8 +198,8 @@ class Flight {
/** /**
* Invokes a method. * Invokes a method.
* *
* @param mixed $func Class method as either an array or string * @param mixed $func Class method
* @param array $params Class initialization parameters * @param array $params Class method parameters
*/ */
public static function invokeMethod($func, array &$params = array()) { public static function invokeMethod($func, array &$params = array()) {
list($class, $method) = $func; list($class, $method) = $func;
@ -282,17 +282,11 @@ class Flight {
*/ */
public static function set($key, $value = null) { public static function set($key, $value = null) {
// If key is an array, save each key value pair // If key is an array, save each key value pair
if (is_array($key)) { if (is_array($key) || is_object($key)) {
foreach ($key as $k => $v) { foreach ($key as $k => $v) {
self::$vars[$k] = $v; self::$vars[$k] = $v;
} }
} }
// If key is an object, save each property
else if (is_object($key)) {
foreach (get_object_vars($key) as $k => $v) {
self::$vars[$k] = $v;
}
}
else if (is_string($key)) { else if (is_string($key)) {
self::$vars[$key] = $value; self::$vars[$key] = $value;
} }

Loading…
Cancel
Save