PHP 5.3 added the __call and __callstatic magic method.
__call the __call method is automatically invoked when the method being invoked does not exist or has insufficient permissions.
__callstatic the __callstatic method is automatically invoked when the calling static method does not exist or if the permissions are insufficient.
__call ($funcname, $arguments)
__callstatic ($funcname, $arguments)
Parameter description:
The name of the method called $funcname String.
The parameter to take when the method is called $arguments Array.
__call Example
<?php class member{protected $memberdata = Array ();
Public Function __call ($func, $arguments) {list ($type, $name) = Explode (' _ ', $func);
if (!in_array ($type, Array (' Set ', ' Get ')) | | $name = = ') {return ';
Switch ($type) {case ' set ': $this->memberdata[$name] = $arguments [0];
Break Case "Get": Return Isset ($this->memberdata[$name])?
$this->memberdata[$name]: ';
Break Default:}} class User extends member{public function sho
W () {if ($this->memberdata) {foreach ($this->memberdata as $key => $member) { echo $key. ': $member. '
<br> '; {}}} class ProfeSsion extends member{public function show () {if ($this->memberdata) {foreach ($this ->memberdata as $key => $member) {echo $key. ': $member. '
<br> ';
$userobj = new User ()}}}
$userobj->set_name (' Fdipzone ');
$userobj->set_age (29);
$userobj->show ();
$probj = new Profession ();
$probj->set_profession (' IT SERVICE ');
$probj->set_price (2500);
$probj->show (); ?>
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/PHP/