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:
?
3 4 5 6 715 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); ?> |