Php 注意:数组到字符串的转换-为什么?

Php 注意:数组到字符串的转换-为什么?,php,reference,notice,Php,Reference,Notice,嗨,我正在尝试执行下面的PHP代码,但是我收到了一个错误。我正在向核心类传递一个引用,我想将其分配给类范围内的一个变量 注意:数组到字符串的转换 提前谢谢 $core = new core($config); $core->execute(); private$config=array() 首先 $this->$config 应删除$config中的第二个$,否则它将尝试使用$config中字符串给定的名称访问变量。(例如,如果$config作为一个值持有“test”,您

嗨,我正在尝试执行下面的PHP代码,但是我收到了一个错误。我正在向核心类传递一个引用,我想将其分配给类范围内的一个变量


注意:数组到字符串的转换

提前谢谢

$core = new core($config);
$core->execute();   
private$config=array()

首先

$this->$config
应删除
$config
中的第二个
$
,否则它将尝试使用
$config
中字符串给定的名称访问变量。(例如,如果$config作为一个值持有
“test”
,您将访问类中的
“test”
变量:
$this->test


传入时,
$config
是什么?(字符串、数组、对象等?

$this->config=$config

这在PHP5.2中可以正常工作。
您使用的是什么版本的php

<?php
class core
{
   private $config;

   public function __construct(&$config)
   {
      $this->config = $config;
   }

   public function execute()
   {
      $this->set_path();
   }

   private function set_path()
   {
      return true;      
   }  
}

$config=array(
     'a'    => '1'
    ,'b'    => '2'
    );

$core = new core($config);
$core->execute();

错误消息的精确副本非常有价值您所说的错误是什么:)注意:第9行core.class.php中的数组到字符串的转换就这些了。。。我不知道为什么会产生通知。。我不想把数组转换成字符串。。我只想将引用传递到类作用域中;应该是$this->config=$config;我想,因为它是一个引用,所以它不需要声明为数组?尝试了这个解决方案,它不起作用。生成了相同的错误消息。您不需要…根据OP,这是一个“通知”啊。。愚蠢的错误。。我也看了一段时间了。。对不起,浪费了你的时间$config是一个数组。
<?php
class core
{
   private $config;

   public function __construct(&$config)
   {
      $this->config = $config;
   }

   public function execute()
   {
      $this->set_path();
   }

   private function set_path()
   {
      return true;      
   }  
}

$config=array(
     'a'    => '1'
    ,'b'    => '2'
    );

$core = new core($config);
$core->execute();