Original text forwarding:http://hi.baidu.com/zwnjiejie/blog/item/5e6555c23fa302120ff477dd.html
Fatal error Using $this when not in object context in D:\xampp\htdocs\test\php\service\FileCommand.php
The general meaning is that $this has no context, because this class is not instantiated.
This error occurs because of the method/property $this, which is used in filecommand.php.
$this is not to be used, but to look at the situation. It is possible to use $this in an instantiated class:
Class person{
private Var $name;
private Var $sex;
Public Function ShowName () {
Echo $this->name;
$this->message ();
}
Public Function message () {
echo "Success";
}
}
If you instantiate the person class and access it directly, you will get the error above, meaning $this there is no context.
Correct usage:
$person = new Person ();
$person. ShowName ();
If you do not want to define the direct use, then you can pass: Person::message (); Note that the inside cannot contain $this
Fatal error:using $this When not in object context in C:\AppServ\www\ABC\model\Model.class.php on line 7