Home  >  Article  >  Backend Development  >  PHP magic function __call() usage example analysis, __call example analysis_PHP tutorial

PHP magic function __call() usage example analysis, __call example analysis_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:06:31842browse

PHP magic function __call() usage example analysis, __call example analysis

This article analyzes the usage of PHP magic function __call() with examples. Share it with everyone for your reference. The details are as follows:

Introduction to the PHP magic function __call(), you will understand it after reading the following example:

<&#63;php
class A{
 public $name;
 function test1($a){
 echo "test1111";
 }
 function test2($a){
 echo "test2222";
 }
 //当某个对象调用某个方法,而当该方法不存在时,则系统会自动调用__call()
 function __call($method,$val){
 echo "类中找不到方法:".$method;
 }
}
$aaa = new A();
$aaa ->test(1);
&#63;>

Output result:

Method not found in

class: test

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/958251.htmlTechArticlePHP magic function __call() usage example analysis, __call example analysis This article analyzes the php magic function __call( )usage. Share it with everyone for your reference. The details are as follows: php magic function...
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