2017-02-13 38 views
1

PHP CODE函数内的数组无法正常工作?

class XXX{ 
public function ggGet($str){ 
    return gGet($str); // This is ok working gGet is global function 
} 
public static $Array = array ("value" => $this->ggGet("email")); // This code is error Why? 

} 

我必须在类中使用的函数的阵列。

我看到这个错误。

Parse error: syntax error, unexpected '$this' (T_VARIABLE) in /var/www/html/

我该怎么办?

谢谢。

回答

2

试试这个:

class XXX{ 

    $MyArray = array(); 

    public function __construct(){ 
     $this->MyArray["value"] = $this->ggGet("email"); 
    } 

    public function ggGet($str){ 
     return gGet($str); 
    } 

} 

使用__construct()每次你需要在一个类中的变种开始值的时间。