我有未來的目錄樹:動態創建新類的正確方法是什麼?
Transport
--Transport.php
--Curl.phpSDK.php
SDK.php是命名空間MySDK和類SDK,在I類有方法:
protected function _getTransport()
{
if (!($this->_transport instanceof Transport\Transport)) {
$className = 'Transport\\' . ucfirst($this->getOption('transport'));
$this->_transport = new $className();
}
return $this->_transport;
}
但我收到錯誤消息:致命錯誤:類' Transport \ Curl'找不到/path/to/repo/lib/SDK.php 而當我將$this->_transport = new $className();
更改爲$this->_transport = new Transport\Curl();
時,我將獲得Transport\Curl
的實例。
請幫助我,我在哪裏犯錯?
哪裏是你的類自動加載磁帶機? – Flosculus
聽起來像名稱空間問題。你在使用作曲家和PSR-0或PSR-4嗎? – mblaettermann