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();
这里的老师是获取不到学生名字的
我用容器将所有的应用组件包起来,然后,当应用组件之间调用的时候,就会有这样的问题。
前面注册进去的应用组件无法调用后面注册的应用,但是后面注册的应用是可以调用前面的。
那么如果说,前面的要使用后面的应用,这个问题怎么解决呢?
回复内容: 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();
这里的老师是获取不到学生名字的
我用容器将所有的应用组件包起来,然后,当应用组件之间调用的时候,就会有这样的问题。
前面注册进去的应用组件无法调用后面注册的应用,但是后面注册的应用是可以调用前面的。
那么如果说,前面的要使用后面的应用,这个问题怎么解决呢?
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();