php anonymous class extends dynamic

时间:2017-03-22 18:40:04

标签: php anonymous-class extending-classes

anyone of you know how to get effect like in these code

 public function create(SomeInterface $obj)
 {
     $class = get_class($obj);
     return new class extends $class {
        //some magic here
     }
 }

Obvious that code will not work in PHP. $obj can be an instance of many different classes. I want to get an instance of class extending the $obj. (It will give me an ability to overload some basic methods)

0 个答案:

没有答案