php.js
php.js copied to clipboard
Parse error: Object [object Object] has no method 'Node_Expr_Closure' in /console.htm on line undefined
<?php
// This class abuses php magic methods to create objects that feel like JS objects
class DynamicObject {
private $properties = array();
public function __construct($assoc = array()) {
if ($assoc)
$this->add($assoc);
}
public function __set($name, $value = null) {
return !$value && is_array($name) ? $this->add($name) : $this->properties[$name] = $value;
}
public function __get($prop) {
return $this->properties[$prop] ? is_callable($this->properties[$prop]) ? 'function()' : $this->properties[$prop] : false;
}
public function __call($name, $args) {
return $this->properties[$name](implode(',', $args), $this);
}
private function add($assoc) {
foreach ($assoc as $k => $v)
$this->properties[$k] = $v;
}
}
/* -----------------------------------------------------------------------------------
TEST
------------------------------------------------------------------------------------ */
$greeting = new DynamicObject();
$greeting->hello = function ($hello = 'world') {
return 'Hello, ' . $hello . "!\n";
};
echo $greeting->hello('JavaScript');
/*
* should be
* Hello, JavaScript!
*
* but gives a parse error instead
*/
?>
Thanks for spotting that, will have it sorted out soon