How to use the __call and __callstatic of the PHP magic method

Source: Internet
Author: User
This article mainly introduces the PHP magic method of __call and __callstatic How to use, the need for friends can refer to the next

Core code


Magic Method __call/* $method Get the method name $arg get the parameter collection of the method */class Human {private Function T () {} public Function __call ($method, $arg) {  Echo ' You want to call the way I don't exist ', $method, ' method <br/> ';   Echo ' also transmitted a parameter <br/> ';   echo Print_r ($arg), ' <br/> ';  } public static function __callstatic ($method, $arg) {  echo ' you want to call me nonexistent ', $method, ' static method <br/> ';   Echo ' also transmitted a parameter <br/> ';   echo Print_r ($arg), ' <br/> ';  }} $ha = new Human ();//example1$ha->t (n/a); Echo ' <br> ';//example2$ha->say (' A ', ' B ', ' C '); Echo ' <br> ' ;//example3$ha::run (' d ', ' e ', ' f ');


You want to call the way I don't exist t method
And a parameter was passed.
Array ([0] = 1 [1] = 2 [2] = 3)

You want to call the way I don't exist say method
And a parameter was passed.
Array ([0] = a [1] = b [2] = = c)

You want to call the run static method that I don't exist
And a parameter was passed.
Array ([0] = + d [1] = e [2] = f)

Related recommendations:

Common Magic Methods for PHP

"PHP Classes and Objects" Magic method

Research on the performance of common magic methods in PHP

Related Article

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.