我有一个带有__construct()方法的PHP类.我传递参数并将它们存储在属性中.像这样:
class BlogList {
private $app_config, $texts;
public function __construct($app_config, $texts) {
$this->$app_config = $app_config;
$this->$texts = $texts;
}
...
}
Run Code Online (Sandbox Code Playgroud)
当我创建这个类的实例时,我看到日志说的是:
PHP Notice: Array to string conversion in /path/to/blogList.php on line 6
Run Code Online (Sandbox Code Playgroud)
我在__construct方法中为这两个赋值得到了这个.$ app_config和$ texts都是数组
为什么要进行此转换?我该如何预防呢?
作业应该是:
public function __construct($app_config, $texts) {
$this->app_config = $app_config;
$this->texts = $texts;
}
Run Code Online (Sandbox Code Playgroud)