Using $this when not in object context in
Posted yolo_bean
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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); ?>
以上是关于Using $this when not in object context in的主要内容,如果未能解决你的问题,请参考以下文章
TypeError: _this.store.getState is not a function when using connect from Redux
Uncaught TypeError: this.source is not a function when using rails4-autocomplete
Tab Key not working when using Xfce remote desktop
TypeError: member is not a function when using `$member`
Uncaught ReferenceError: Clipboard is not defined: when using clipboard.js with Rails 6
Bootstrap:'TypeError undefined is not a function'/'has no method 'tab'' when using bootstrap-tabs