"" Fatal Error:call to a member function * on a non-object

Source: Internet
Author: User
Tags variable scope
"Emergency help" Fatal Error:call to a member function * * * on a Non-object
This post was last edited by keric2008 on 2013-08-26 18:33:02

The source code is very long, abstract, the approximate process is this.

{
$instest = new test ();
$insobject = new Object ();
$instest->test ();
}

Class test{
function Test () {
$insobject->hello ();
}
}

Class object{
function Hello () {
echo "Hello";
}
}
This will cause title error: Fatal Error:call to a member function Hello () on a non-object in/home/latelx64/workspace/zhebo/init.php on Line 158

Is it possible to invoke the public function of other instances in the instance?

If not, how should it be solved in a similar way???
I am a newly-learned PHP, I hope you master to give guidance!!! PHP class

Share to:


------Solution--------------------
This is not object-oriented!
It's just a matter of variable scope!
Class test{
function Test () {
$insobject->hello ();
}
}
The $insobject is a local variable and is not assigned a value.
Of course, there's 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.