Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse error: Object [object Object] has no method 'Node_Expr_Closure' in /console.htm on line undefined #5

Open
nfeldman opened this issue Jul 25, 2012 · 1 comment

Comments

@nfeldman
Copy link

<?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
 */
?>
@niklasvh
Copy link
Owner

Thanks for spotting that, will have it sorted out soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants