你可以使用 $this 来访问类的属性和方法。 在非对象上下文中使用 '$this' 会导致的问题: 如果在非对象上下文中(比如在一个普通的函数或全局作用域中)使用 $this,PHP 会抛出一个错误:“Using thiswhennotinobjectcontext”。这是因为‘this when not in object context”。这是因为 `thiswhen
板邓:PHP解决Using $this when not in object context in【转】 错误信息:$this引用没有上下文 原因:在PHP5中,static声明的静态方法里不可以使用$this 需要使用self来引用当前类中的方法或是变量。 示例代码如下: <?php namespace syhl\admin\page\record;//命名空间require_oncedirname(__FILE__).'/../....
phpclass test {private $a;function t1( ){$this->a=1;//调用属性方式不正确(下面同理) $this->a=1;print $this->$a;// print($this->a); 这里不加括号写空格也是可以的;}function t2( ){$this->$a=2;//$this->a=2;print $this->$a;// print($this->a);}}$re= n...
'3306', 'wx_entercode_cn', 'guwansifang', 'wx_entercode_cn'); } public function test(){ $this->db->insert('chat_record')->cols(array( 'to_msg'=>$message_data['to_client_id'], 'from_msg'=>$message_data['from_client_id'], 'content...
Using $this when not in object context ,一般来说,当你使用某个类,而这个类并没有进行实例化的时候就会出现这种错误。据我的理解,你可能是还没有理解静态变量(函数)和常规类的实例变量的区别,在PHP里,有static修饰的变量和函数不能出现$this。建议你再看看PHP帮助手册里,有关 static 静态...
Welcome Guest, Not a member yet? Register Sign In CodeIgniter Forums Archived Discussions Archived Development & Programming PHP Fatal error: Using $this when not in object context PHP Fatal error: Using $this when not in object context
$func=function($say){echo $this->name,':',$say,PHP_EOL;};$func('good');// Fatal error: Uncaught Error: Using $this when not in object context 在这个匿名函数中,我们使用了 \$this->name 来获取当前作用域下的 $name 属性,可是,这个 $this 是谁呢?我们并没有定义它,所以这里会直接报错。
类中在成员方法体中使用成员属性或者方法直接用$this表示当前对象;示例如下:<?class one{ public $a="aaa"; function xy() { echo $this->a;//这里报错!不让用$this ? } function a(){ }}$a = new one();$a->xy();//输出:aaa?> 我试过了没错不报错...
错误:PHP Fatal error: Using $this when not in object context 代码如下: 1<?php2classsomeClass3{4private$success= "success\n";56publicfunctiongetReflection()7{8returnnewReflectionFunction(function(){9print$this->success;10});11}12}1314$reflection=call_user_func([newsomeClass(),'getReflection'...
大哥.你是写js写多了吧...m->property();这样才是对的...比如,你$mysql->query()或者$smarty->assign()不是都这样吗.晕.