板邓:PHP解决Using $this when not in object context in【转】

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

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

 

示例代码如下:

<?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-06-14 13:18  贵隆  阅读(1504)  评论(0编辑  收藏  举报