Is it possible to extend a class dynamically?

前端 未结 8 1338
耶瑟儿~
耶瑟儿~ 2020-12-05 10:09

I have a class which I need to use to extend different classes (up to hundreds) depending on criteria. Is there a way in PHP to extend a class by a dynamic class name?

8条回答
  •  天命终不由人
    2020-12-05 10:57

    While it's still not possible and not exactly your answer i needed the same thing and didn't wanted to use eval, monkey-patching etc. So i used a default class by extending it in conditions.

    Of course it means if you have 100 classes to extend you need to add 100 conditions with another extending operation but for me this looked like the right way.

    
    

提交回复
热议问题