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