Static class initializer in PHP

后端 未结 8 865
南方客
南方客 2020-12-02 05:12

I have an helper class with some static functions. All the functions in the class require a ‘heavy’ initialization function to run once (as if it were a constructor).

<
8条回答
  •  庸人自扰
    2020-12-02 05:57

    Note - the RFC proposing this is still in the draft state.


    class Singleton
    {
        private static function __static()
        {
            //...
        }
        //...
    }
    

    proposed for PHP 7.x (see https://wiki.php.net/rfc/static_class_constructor )

提交回复
热议问题