我知道这是一个常见问题,但我看到的问题(约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之前! –