galancev/instance

实例化特质

v2.0 2019-12-30 18:29 UTC

This package is auto-updated.

Last update: 2024-09-29 06:08:31 UTC


README

用于轻松实例化类的特质。

只需在任何类中添加此特质即可

class Test {
    use Instance;
}

即可使用魔法方法

创建类的新实例

Test::factory()

创建类的单例

Test::instance()

使用示例

class StringHelper {
    use Instance;
    
    public function reverse($string) {
        return strrev($string);    
    }
}

echo StringHelper::instance()->reverse('1234567890');