!--? phpclass classroom{public $room = []; function Addteacher ($teacher) {$this--->room[' teacher ') = $teacher; } function Addstudents ($student) {$this->room[' student ') = $student; }}class teacher{Public $name = ' AAAA '; Public $room =[]; function __construct ($room) {$this->room = $room; } function SayHello () {echo ' hello '. $this->room[' student ']->name. ' Student '. Php_eol; }}class student{Public $name = ' BBB '; Public $room =[]; function __construct ($room) {$this->room = $room; } function SayHello () {echo ' hello '. $this->room[' teacher ']->name. ' Teacher '. Php_eol; }} $Classroom = new classroom; $Classroom->addteacher (New Teacher ($Classroom->room)); $Classroom Addstudents (New Student ($Classroom->room)), $Classroom->room[' teacher ']->sayhello (); $Classroom->room [' Student ']->sayhello ();
The teacher here is not getting the student's name.
I wrap all the application components in a container, and then, when called between application components, there is a problem.
The application component that was previously registered cannot invoke the app that is registered later, but the application that is registered later can call the previous one.
So if the previous application is to be used, how can the problem be solved?
Reply content:
!--? phpclass classroom{public $room = []; function Addteacher ($teacher) {$this--->room[' teacher ') = $teacher; } function Addstudents ($student) {$this->room[' student ') = $student; }}class teacher{Public $name = ' AAAA '; Public $room =[]; function __construct ($room) {$this->room = $room; } function SayHello () {echo ' hello '. $this->room[' student ']->name. ' Student '. Php_eol; }}class student{Public $name = ' BBB '; Public $room =[]; function __construct ($room) {$this->room = $room; } function SayHello () {echo ' hello '. $this->room[' teacher ']->name. ' Teacher '. Php_eol; }} $Classroom = new classroom; $Classroom->addteacher (New Teacher ($Classroom->room)); $Classroom Addstudents (New Student ($Classroom->room)), $Classroom->room[' teacher ']->sayhello (); $Classroom->room [' Student ']->sayhello ();
The teacher here is not getting the student's name.
I wrap all the application components in a container, and then, when called between application components, there is a problem.
The application component that was previously registered cannot invoke the app that is registered later, but the application that is registered later can call the previous one.
So if the previous application is to be used, how can the problem be solved?
room[' teacher '] = $teacher; } function Addstudents ($student) {$this->room[' student ') = $student; }} class teacher{public $name = ' AAAA '; Public $room =[]; function __construct ($room) {$this->room = $room; } function SayHello () {echo ' hello '. $this->room->room[' student ']->name. ' Sdent '. Php_eol; }} class student{public $name = ' BBB '; Public $room =[]; function __construct ($room) {$this->room = $room; } function SayHello () {echo ' hello '. $this->room->room[' teacher ']->name. ' Teacher '. Php_eol; }} $Classroom = new classroom; $Classroom->addteacher (New Teacher ($Classroom)); $Classroom->addstudents (New Student ($Classroom)); $Classroom->room[' teacher ']->sayhello (); $Classroom->room[' student ']->sayhello ();