是否可以这样做?
class Foo
{
public function __construct($bar)
{
$barish = new $bar();
$barish->woo();
}
}
class Bar
{
function woo()
{
echo "wooooo";
die();
}
}
// Here the magic should happen
$foo = new Foo(Bar);
我希望wooooo
但是我得到"使用未定义的常量Bar"。
答案 0 :(得分:2)
您遗失''
:
class Foo
{
public function __construct($bar)
{
$barish = new $bar();
$barish->woo();
}
}
class Bar
{
function woo()
{
echo "wooooo";
die();
}
}
// Here the magic should happen
$foo = new Foo('Bar');