[] Fatalerror: Calltoamemberfunction * onanon-object

Source: Internet
Author: User
[Urgent help] Fatalerror: Calltoamemberfunction *** onanon-object This post was last edited by keric2008 at 2013-08-2618: 33: 02 source code [urgent help] Fatal error: call to a member function *** on a non-object
At the end of this post, the source code edited by keric2008 at 18:33:02 is very long. the abstract process is like this.

{
$ Instest = new test ();
$ Insobject = new object ();
$ Instest-> test ();
}

Class test {
Function test (){
$ Insobject-> hello ();
}
}

Class object {
Function hello (){
Echo "hello ";
}
}
In this case, the following error occurs: Fatal error: Call to a member function hello () on a non-object in/home/latelx64/workspace/zhebo/init. php on line 158

Can't the public functions of other instances be called in the instance?

If not, how can we solve the problem in a similar way ???
I am new to PHP, and hope you can give guidance !!! Php class:
------ Solution --------------------
This has nothing to do with object-oriented!
It's just a variable scope problem!
Class test {
Function test (){
$ Insobject-> hello ();
}
}
$ Insobject is a local variable, and no value is assigned.
Of course there is no hello method.
------ Solution --------------------
class test{
    function test(){
        object::hello();
    }
}

class object{
    Public static function hello(){
        echo "hello";
    }
}

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.