&$val) { // Bind '$this' for closures if ($val instanceof Closure) { $val = $val->bindTo($this); } // Add the parameter to the object $this->$name = $val; } } // -------------------------------------------------------------------------- /** * Magic method to invoke appended closures * * @param string * @param array * @return mixed */ public function __call($name, $params = []) { // Allow array operations on the object if (substr($name, 0, 6) === 'array_' && is_callable($name)) { $args = array_merge($this->getArrayCopy(), $params); return call_user_func_array($name, [$args]); } // Call closures attached to the object if (is_callable($this->$name)) { return call_user_func_array($this->$name, $params); } return NULL; } } // End of JSObject.php