Variable variable class extensions in PHP--is it possible?

前端 未结 8 1908
囚心锁ツ
囚心锁ツ 2020-12-06 14:22

Is something like the following possible in PHP?

$blah = \'foo1\';

class foo2 extends $blah {
    //...
}

class foo1 {
    //...
}

This g

8条回答
  •  攒了一身酷
    2020-12-06 15:07

    I don't see how this would be particularly useful, but to answer your question... no. There's no way to dynamically do that because the generated class has to be instantiated before the variable is evaluated (if that makes sense).

    To put it simply: The class must exist before the code can be properly executed.

提交回复
热议问题