首页 > 其他 > 详细

Using $this when not in object context in

时间:2017-08-13 09:41:20      阅读:261      评论:0      收藏:0      [点我收藏+]

错误信息:$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);

?>

 

Using $this when not in object context in

原文:http://www.cnblogs.com/yolo-bean/p/7352237.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!