PHP: call child constructor from static method in parent

前端 未结 4 1826
天命终不由人
天命终不由人 2021-01-17 17:45

I want to have a static method in a parent class that creates instances of whatever subclass i call this method on.

An example to make this more clear:

cl         


        
4条回答
  •  耶瑟儿~
    2021-01-17 18:23

    Umm, wouldn't that be:

    class sub extends parent {
      public static function make_objects($conditions) {
        //sub specific stuff here
        //....
      }
    }
    

提交回复
热议问题