namespace Test { class Test {}
}namespace Chou { use Test\Test; class Mee { public $class = 'Test'; public function getClass()
{ return new $this->class();
}
}
$tmp = new Mee();
$tmp->getClass();
}我試圖在getClass方法中通過變量動態(tài)實例化另一個命名空間的類,但是觸發(fā)了“Class not found”錯誤。我覺得時$class變量的問題,所以又把測試代碼簡化了一下:namespace Chou { use Test\Test; $test = 'Test'; $tmp = new $test();
}果然出現(xiàn)了和預期一樣的錯誤。我知道可以通過完全限定的方式來解決,但是我仍然想明白這是什么原理,還望高手解惑。
- 1 回答
- 0 關(guān)注
- 107 瀏覽
添加回答
舉報
0/150
提交
取消