zephir: Problem with magic __call during creating multiple instances

I’m getting sigsegv signal when I’m trying to create several instances which using magic __call:

$di = new MyDi();
$di->set("tmp", "some service");

$t1 = new Test($di);
$t2 = new Test($di);

var_dump($t1, $t2);

Program received signal SIGSEGV, Segmentation fault.


class Test
{

    protected _tmp;

    public function __construct(di)
    {
        let this->_tmp = di->getTmp();
    }
}
class MyDi
{

    protected _data { get };

    public function __construct(array data = [])
    {
        let this->_data = data;
    }

    public function has(string key)
    {
        return isset this->_data[key];
    }

    public function get(string key, var defaultValue = null)
    {
        var value;

        if fetch value, this->_data[key] {
            return value;
        }

        return defaultValue;
    }

    public function set(string key, var value)
    {
        let this->_data[key] = value;
    }

    public function __call(string! method, value = null)
    {
        var service;

        if starts_with(method, "get") {
            let service = lcfirst(substr(method, 3));

            if this->has(service) {
                return this->get(service, value);
            } else {
                throw new Exception(sprintf("The '%s' service is required", service));
            }
        }

        if starts_with(method, "set") {
            this->set(lcfirst(substr(method, 3)), value);
            return null;
        }

        throw new Exception("Call to undefined method or service '" . method . "'");
    }
}

Similar issue with __call: https://github.com/phalcon/zephir/issues/438#issuecomment-48435254

It works fine if I replace getTmp() to:

let this->_tmp = di->get("tmp");

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 17 (16 by maintainers)

Most upvoted comments

Thank you for the status update

I updated to PHP 7.4.5 and it seems OK 🙄