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

前端 未结 8 1919
囚心锁ツ
囚心锁ツ 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:00

    If you don't have too many values for $blah, you could extend each one in a different file then require_once "classes/foo_$blah.php"

    Otherwise, you're stuck with the eval() solution... good luck with that... :)

提交回复
热议问题