Fatal error:using $this When not in object context in C:\AppServ\www\ABC\model\Model.class.php on line 7

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.