Is it possible to create static classes in PHP (like in C#)?

前端 未结 6 1622
南方客
南方客 2020-11-28 01:47

I want to create a static class in PHP and have it behave like it does in C#, so

  1. Constructor is automatically called on the first call to the class
  2. No
6条回答
  •  暖寄归人
    2020-11-28 02:14

    object cannot be defined staticly but this works

    final Class B{
      static $var;
      static function init(){
        self::$var = new A();
    }
    B::init();
    

提交回复
热议问题