Home  >  Article  >  Backend Development  >  PHP magic function __call() usage example

PHP magic function __call() usage example

WBOY
WBOYOriginal
2016-07-25 08:52:07936browse
  1. class A{
  2. public $name;
  3. function test1($a){
  4. echo "test1111";
  5. }
  6. function test2($a){
  7. echo "test2222";
  8. }
  9. //When an object calls a method and the method does not exist, the system will automatically call __call()
  10. function __call($method,$val){
  11. echo "Method not found in class: ".$method;
  12. }
  13. }
  14. $aaa = new A();
  15. $aaa ->test(1);
  16. ?>
Copy the code

Output result: Method not found in class: test



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn