Use $ this-> display () in file A to call the method of another class file. how can this problem be solved?

Source: Internet
Author: User
Use $ this-& gt; display () in file A to call the method of another class file. what should I do? File A: PHPcodeclassindexAction {publicfunctionindex () {echoabc; $ this-& gt; display (); is this line} use $ this-> display () in file () how can I call another class file method?
File:
PHP code
  Class indexAction {public function index () {echo 'abc'; $ this-> display (); // this row }}


Class B files:
PHP code
  Class view {public function display () {echo 'Template output succeeded ';}}


How can I instantiate A file so that $ this-> display () can call another Class B file

------ Solution --------------------
$ This-> display ()? This design is strange.
I'm afraid I have to inherit class indexAction extends view.
Alternatively, you can select the magic method _ call ()
Learn now:
PHP code
Class indexAction {// add a magic method public function _ call ($ mName, $ mArg) {$ view = new view (); if (method_exists ($ view, $ mName) call_user_func (array ($ view, $ mName ));}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.