以法比安斯基Potencier的example:在PHP依賴注入中,是否需要「require_once」定義依賴關係的php文件?
class User
{
function __construct($storage)
{
$this->storage = $storage;
}
// ...
}
假設存儲類在不同的PHP文件(比如說,storage.php)定義的,我需要把它列入該文件是注射通過require_once完成?
感謝,
JDelage
謝謝Rudi。所以我不需要require_once來使注射本身工作。 – JDelage 2010-09-09 17:42:09
在上面的例子中,你不需要任何需求,因爲'$ storage'只是一個變量 - 沒有'user.php'的definitino需要理解。如果你使用[type hinting] [1](一個完全不同的主題)...那麼你需要'require'定義類型的源代碼。 [1]:http://php.net/manual/en/language.oop5.typehinting.php – Rudu 2010-09-09 17:50:26