【问题标题】:Array inside function not working?函数内部的数组不起作用?
【发布时间】:2017-02-13 21:59:46
【问题描述】:

PHP 代码

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?

}

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

我看到了这个错误。

解析错误:语法错误,/var/www/html/ 中出现意外的 '$this' (T_VARIABLE)

我必须做什么?

谢谢。

【问题讨论】:

    标签: php class


    【解决方案1】:

    试试这个:

    class XXX{
    
       $MyArray = array(); 
    
       public function __construct(){
          $this->MyArray["value"] = $this->ggGet("email");
       }
    
       public function ggGet($str){
           return gGet($str); 
       }
    
    }
    

    每次需要在类中的 var 中启动值时,请使用 __construct()。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-21
      • 2023-01-29
      • 2014-12-05
      • 2016-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多