大致意思是 $this 没有上下文,原因是没有对此类进行实例化。

出现此错误的原因是:在FileCommand.php中使用 $this->方法/属性。

$this 不是不可以用,而是要看情况用。在实例化的 类中使用 $this是可以的

class Person{

     private var    $name;

     private var    $sex;

    public function showName(){

          echo $this->name;

          $this->message();

    }

     public function message(){

             echo "success";

     }

}

如果不实例化 Person 类而直接访问的话就会出上面的错误,意思是 $this没有上下文。

正确用法:

   $person = new Person();

   $person.showName();  

如果不想定义直接用的话,则可通过:   Person::message(); 注意里边不能含有 $this

PHP允许使用static关键字,该关键字适用于允许在未初始化类的情况下就可以调用的方法;

请注意,在一个静态方法中,不能使用this关键字,因为可能会没有可以引用的对象实例。

class test {
private $a; function t1( ){
$this->a=1;
print $this->a."";
}
static function t2( ){
$test=new test(); //静态方法 所以要实例化这个类;而不能直接用 $this->
$test->a=2;
print $test->a."";
}
}
$re= new test( );
$re->t1();
$re::t2();

一般非常量、静态字段、静态方法,都是用指向来 -> 来调用内部成员,例如:$re -> t1()

 
只有常量、静态字段、静态方法,采用 :: 调用,例如:$re :: t1()

Fatal error Using $this when not in object context in的更多相关文章

  1. Fatal error: Using $this when not in object context in 解决方法

    Fatal error: Using $this when not in object context in 解决方法 粗心造成的错误 $this 只存在于下面情况 $obj = new object ...

  2. Fatal error: Cannot use object of type PHPExcel_RichText as array

    Fatal error: Cannot use object of type PHPExcel_RichText as array 上传导入Excel的时候会出现此问题,问题的原因是Excel表格中有 ...

  3. 无法启动"D\projects\hello\Debug\hello.exe" 系统找不到指定的文件。[LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏]

    这两天安装Visual Studio遇到这样的一个问题,用自己的电脑和公司的电脑都出现同样的问题.两台电脑都是新系统,按理来说是没有问题的.但是一出现问题,对于我这个小白来说,还是耗费了挺多精力都无果 ...

  4. Fatal error 829---数据库 ID 8,页 (1:80740) 已标记为 RestorePending,可能表明磁盘已损坏(日志备份和热备、双机的重要性)

    问题现象: 在业务数据库中查询:SELECT a.NAME FROM SYSOBJECTS a WHERE a.NAME LIKE '%2015' AND a.XTYPE='u' 提示:消息 21,级 ...

  5. 完美解决VS2003.Net fatal error LNK1201: 写入程序数据库“.pdb”时出错

    我的开发环境是Win7旗舰64位+VS2003.Net,经常卡pdb错误,文末给出一个完美的解决方案和一个懒人补丁包.问题描述如下:在重新编译的时候,经常报错: fatal error LNK1201 ...

  6. 黄聪:wordpress中PHP运行错最有效解决办法Fatal error: Out of memory (allocated 6029312)(转)

    近日在升级wordpress 3.2.1和若干插件的过程中,发现了一个wordpress的错误:Allowed memory size of XXX bytes exhausted Fatal err ...

  7. angular4 JavaScript内存溢出问题 (FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory)

    最近在写基于angular4的项目的时候,在build --prod的时候,突然措手不及的蹦出个报错,大致错误如下: 70% building modules 1345/1345 modules 0 ...

  8. git推送报错: No path specified. See 'man git-pull' for valid url syntax或does not appear to be a git repository以及remote: error: insufficient permission for adding an object to repository databa

    本地(windows)代码想推送到linux自己搭建的git服务端,第一步是建立本地与服务端的关联,第二步是本地推送到服务端. 第一步需要看你的本地工程是否从git上clone来的,如果是clone来 ...

  9. DVWA--登录页面错误问题 469 | | PHP Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:\web\DVWA\dvwa\includes\dvwaPage.inc.php:469

    // MySQL PDO Prepared Statements (for impossible levels) $db = new PDO('mysql:host=' . $_DVWA[ 'db_s ...

随机推荐

  1. CF555B 贪心

    http://codeforces.com/problemset/problem/555/B B. Case of Fugitive time limit per test 3 seconds mem ...

  2. java- Servlet-session

    Servlet 相关:http://blog.csdn.net/ggGavin/article/category/2134213 Servlet——Session(1)之基础知识 Servlet——S ...

  3. ubuntu 12.04 rails server 时候报错 execjs

    新的应用创建好了,使用rails server启动看看,oops!原来是没有javascript运行环境. 1 2 $ rails server  /usr/local/lib/ruby/gems/1 ...

  4. 我们要注意的Mysql基本安全设置

    1.设置或修改Mysql root密码:默认安装后空密码,以mysqladmin命令设置密码: mysqladmin -uroot password "password" Mysq ...

  5. mysql数据库对时间进行默认的设置

    //----------------------------------------------------------sql语句----------------------------------- ...

  6. mac安装IDEA

    Mac上安装Java7 首先我们需要去oracle下载最新的jdk,笔者拿到的最新的版本是1.7.0_45-b18,这里没有什么好说的,直接下载安装即可,安装完毕后需要在.bash_profile或者 ...

  7. C++:在堆上创建对象,还是在栈上?

    这篇文章来自于一次讨论:http://www.devbean.net/2013/01/qt-study-road-2-model-view/#comment-17532.关于究竟是在堆上还是在栈上创建 ...

  8. e643. 以匿名类处理事件

    If an event handler is specific to a component (that is, not shared by other components), there is n ...

  9. 修改MySQL的默认密码的四种小方法

    投稿:lijiao 字体:[增加 减小] 类型:转载 时间:2015-09-05我要评论 对于windows平台来说安装完MySQL后,系统就已经默认生成了许可表和账户,下文中就教给大家如何修改MyS ...

  10. 奇葩问题:ListView中Item与Item中的Button不能单击问题

    android中ListView是一个经常要用到的一个组件,用到该组件时经常会碰到ListView的Item和Item中的Button不能单击的问题. 本人在使用时同样也遇到过这样的情况,共有三种情况 ...