"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";
}
}