function keep() { foreach (func_get_args() as $var) { if (is_object($var)) { if (method_exists($var, 'keep')) { $var->keep(); } } elseif (is_array($var)) { foreach ($var as $k => $v) { //echo 'keep '.$k; keep($v); } } } }
public static function onShutdown() { keep($_SESSION); // do not destroy models }
public function keep() { // protect from destroying after script ends (to allow saving in $_SESSION) $this->isDestroyed = true; foreach ($this->_properties as $property) { keep($property); // destroy backlinks to model } }