Using $this when not in object context in

错误信息:$this引用没有上下文

原因:在PHP5中,static声明的静态方法里不可以使用$this 需要使用self来引用当前类中的方法或是变量

 引用的方法里不可以带$this(示例代码中为getres()方法)

示例代码如下:

<?php
namespace syhl\admin\page\record;  // 命名空间

require_once  dirname(__FILE__).'/../../../../common/smarty_loader.php';  

class record {
  
    
     public static function exec($smarty) {    
        
        $ttr=self::getres();
        $smarty->assign("arr",$ttr);      
        $smarty->display ( 'rec_mgr.html' );
    }
   function getres(){
      $arr = array (  
       "1" => 'test',  
       '2' => 'me',  
       array (  
        "3" => "beij",  
        "4" => "zz"  
       ),  
       array (  
        "5",  
        "6" => "ewrwer",  
        "7" => "ssss"  
       )  
      );  
      return $arr;
    }
}
record::exec($smarty);

?>

 

posted @ 2017-08-13 02:38  yolo_bean  阅读(320)  评论(0编辑  收藏  举报