This post was last edited by keric2008 on 2013-08-26 18:33:02
PHP class
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!!!
Reply to discussion (solution)
If you have to do this, then the function needs to pass the argument and pass an object in.
{$instest = new test (), $insobject = new Object (); $instest->test ($insobject);} Class Test{function Test ($insobject) {$insobject->hello ();}} Class Object{function Hello () {echo "Hello";}}
In general, from the perspective of design, the use of inheritance will be better.
Can I use inheritance for an example, thank you very much
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!!!
In the case of inheritance, the data in the instance of the parent class declaration will not exist in the instance using the subclass declaration.
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.
Do you want to declare global variables in each function?
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.
Class test{
function Test () {
Global $insobject;
$insobject->hello ();
}
}
So every function must be declared not very complicated!! Is there nothing to be tactful about?
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.
$_env['? Volume name ']
? Things can be super-global use, like?:
$_globals['?];$_get[', volume name '];$_post['? Volume name '];$_request['?
If you have to do this, then the function needs to pass the argument and pass an object in.
{$instest = new test (), $insobject = new Object (); $instest->test ($insobject);} Class Test{function Test ($insobject) {$insobject->hello ();}} Class Object{function Hello () {echo "Hello";}}
In general, from the perspective of design, the use of inheritance will be better.
You can't do it with this method. warning:missing Argument 1 for Test::test (), called in C:\wamp\www\zhebo\index.php on line 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"; }}