我知道這是一個常見問題,但我看到的問題(約10)比我一直困惑。如何在php中使用構造函數來初始化實例變量
我的問題包含在代碼中作爲註釋。
我有三個字段
public class Model
{
public $prop1;
public $prop2;
public $prop3;
public function _construct($params) // doubt 1: Do I have to pass an array to a constructor, can't I pass the parameters individually
{
// doubt 2: How to assign the value to the instance variables
}
}
$model = new \App\Model($whatToPuthere); //doubt 3: How to provide the constructor parameters
你讀過關於[類和對象](http://php.net/manual/en/language.oop5.php)的PHP文檔嗎?現在您需要知道的所有內容都在這裏進行了解釋,並附有示例。 – axiac
有一個關於一切的文檔「如果我們遵循這種思路,沒有理由有stackoverflow,如果我停下來閱讀我面對的每一個問題的文檔,將需要很長的時間來完成我的任務。我的問題是非常基本的應該有一個概念,但在這一刻我沒有時間閱讀文檔 –
除了我閱讀文檔,但我也感到困惑它。PHP中的構造函數對我來說很困惑,你應該有詢問我是否閱讀了文檔,在downvote之前! –