【问题标题】:PHP unexpected T_FUNCTION/construct issue?PHP 意外的 T_FUNCTION/构造问题?
【发布时间】:2012-06-19 15:00:59
【问题描述】:

我在 cake php 中有如下代码:

public $ceff_instance = array();

public function __construct() {

    $this->ceff_instance = $this->wsMethod_GO();
}

protected $filedMethodMappings = $this->$ceff_instance;

$wsMethod_GO 返回一个数组。但是,它说有一个unexpected T_FUNCTION 在我尝试将$ceff_instance 数组放入$filedMethodMappings 的行中。这是什么原因?

我一辈子都想不通。

【问题讨论】:

    标签: php error-handling


    【解决方案1】:
    protected $filedMethodMappings = $this->$ceff_instance;
    

    您不能在方法之外设置使用 $this

    public $ceff_instance = array();
    protected $filedMethodMappings = NULL;
    
    public function __construct() {
        $this->ceff_instance = $this->wsMethod_GO();
        $this->filedMethodMappings = $this->$ceff_instance;
    }
    

    演示:http://codepad.org/1V6ChkY0

    【讨论】:

    • @Sarfraz:谢谢 :-) 虽然我可能应该回去工作了 :-P
    猜你喜欢
    • 1970-01-01
    • 2011-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-17
    • 1970-01-01
    • 1970-01-01
    • 2012-06-08
    相关资源
    最近更新 更多