[Urgent help] Fatalerror: Calltoamemberfunction *** onanon-object This post was last edited by keric2008 at 18:33:02
Php class
The source code is very long. Abstract: The 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 !!!
Reply to discussion (solution)
If you have to do this, the function needs to pass the parameter and upload an object.
{$instest = new test();$insobject = new object();$instest->test($insobject);}class test{function test($insobject){$insobject->hello();}}class object{function hello(){echo "hello";}}
Generally, from the design point of view, it is better to use the inheritance method.
Can I use inheritance as an example? thank you very much.
The source code is very long. Abstract: The 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 !!!
If inheritance is used, the data in the instance declared by the parent class does not exist in the instance declared by the subclass.
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.
Do I need to declare global variables in each function?
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.
Class test {
Function test (){
Global $ insobject;
$ Insobject-> hello ();
}
}
In this way, it is not very complicated to declare in every function !! Is there no euphemism?
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.
$ _ ENV ['? Volume name']
? It can be used globally ,? Like? Include:
$ _ GLOBALS ['? Volume name ']; $ _ GET ['? Volume name ']; $ _ POST ['? Volume name ']; $ _ REQUEST ['? Volume name'] and so on
If you have to do this, the function needs to pass the parameter and upload an object.
{$instest = new test();$insobject = new object();$instest->test($insobject);}class test{function test($insobject){$insobject->hello();}}class object{function hello(){echo "hello";}}
Generally, from the design point of view, it is better to use the inheritance method.
You cannot use this method. Warning: Missing argument 1 for test: test (), called in C: \ wamp \ www \ zhebo \ index. php on line 24 and defined in C: \ wamp \ www \ zhebo \ x \ init. php on line 170
class test{ function test(){ object::hello(); }}class object{ Public static function hello(){ echo "hello"; }}