Home > Backend Development > PHP Tutorial > PHP magic function __call() usage example analysis_PHP tutorial

PHP magic function __call() usage example analysis_PHP tutorial

WBOY
Release: 2016-07-13 10:06:32
Original
1052 people have browsed it

PHP magic function __call() usage example analysis

This article mainly introduces the usage of PHP magic function __call() and analyzes the function of __call() function with examples. and usage techniques, which have certain reference value. Friends in need can refer to it

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:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

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);

?>

1 2

3

4

5

6 7

89 10 11 12 13 14
15
16
17
<🎜>class A{<🎜> <🎜>public $name;<🎜> <🎜>function test1($a){<🎜> <🎜>echo "test1111";<🎜> <🎜>}<🎜> <🎜>function test2($a){<🎜> <🎜>echo "test2222";<🎜> <🎜>}<🎜> <🎜>//When an object calls a method and the method does not exist, the system will automatically call __call()<🎜> <🎜>function __call($method,$val){<🎜> <🎜>echo "Method not found in class: ".$method;<🎜> <🎜>}<🎜> <🎜>}<🎜> <🎜>$aaa = new A();<🎜> <🎜>$aaa ->test(1); ?>
Output result: Method not found in class: test I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/958134.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/958134.htmlTechArticlePHP magic function __call() usage example analysis This article mainly introduces the usage of php magic function __call() , the example analyzes the function and usage skills of the __call() function, which has certain reference value...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template