[請益] php用字串 new class 和 call function

作者: yhn0tgb60 (呦厚厚)   2014-06-08 16:17:59
請問 php可以用 字串 new class 和 call function 嗎
例如 $className= "NewClass";
$obj = new [$className]; => 等同於 new NewClass
$funcName= "CallFunc";
$obj[$funcName]; => 等同於 $obj->CallFunc()
有辦法這樣做嗎?
作者: banjmin (HD)   2014-06-08 16:51:00
這麼做的意義在哪?
作者: dinos (守護神)   2014-06-08 16:53:00
用大括號
作者: jfcherng (小霹靂)   2014-06-08 21:11:00
variables variable: http://goo.gl/TZ9Yc
作者: up9cloud (九天)   2014-06-09 07:13:00
try: (new $classname)->$funcname();

Links booklink

Contact Us: admin [ a t ] ucptt.com