U
U
ubuntu_lts2020-07-28 15:21:00
phpstorm
ubuntu_lts, 2020-07-28 15:21:00

Method not found in trait Singleton :)?

trait TSingleton
{
    private static $instance;

    public static function getInstance()
    {
        if (!self::$instance) {
            self::$instance = new self();
        }
        return self::$instance;
    }
}

class Registry
{
    use TSingleton;
    public static $properties = [];

    public function setProperty($name, $value)
    {
        self::$properties[$name] = $value;
    }

    public function getProperty($name)
    {
        return self::$properties[$name] ?? null;
    }

    public function getProperties()
    {
        return self::$properties;
    }
}
Registry::getInstance()->getProperties();

Everything works, but the storm shines: getProperties() not found in TSingleton.
What should be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JhaoDa, 2020-07-28
@ubuntu_lts

What should be done?

Learn about staticand its difference from self.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question