PHP 5.3 Adds the __call and __callstatic magic methods.
__call The __call method is called automatically when the method to invoke does not exist or has insufficient permissions.
__callstatic The __callstatic method is called automatically when a static method that is called does not exist or has insufficient permissions.
__call ($funcname, $arguments)
__callstatic ($funcname, $arguments)
Parameter description:
$funcname String called by the method name.
$arguments The parameter that the Array takes when calling the method.
__call Example
<?phpclass 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 show () {if ($this->memberdata) {f Oreach ($this->memberdata as $key = $member) {echo $key. ': ' $member. ' <br> '; }}}}class profession extends member{public function show () {if ($this->memberdata) {fo Reach ($this->memberdata as $key = + $member) {echo $key. ': ' $member. ' <br> '; }}}} $userobj = new User (); $userobj->set_name (' Fdipzone '); $userobj->set_age; $userobj->show (); $prob j = new Profession (); $probj->set_profession (' IT SERVICE '); $probj->set_price (2500); $probj->show ();? >
__callstatic example
<?phpclass member{protected static $memberdata = Array (); public static function __callstatic ($func, $arguments) {list ($type, $name) = Explode (' _ ', $func); if (!in_array ($type, Array (' Set ', ' Get ')) | | $name = = ') {return '; } $feature = Get_called_class (); Switch ($type) {case ' set ': Self:: $memberdata [$feature] [$name] = $arguments [0]; Break Case ' get ': return Isset (self:: $memberdata [$feature] [$name])? Self:: $memberdata [$feature] [$name]: '; Break Default:}}}class User extends member{public static function show () {$feature = Get_called_class (); if (self:: $memberdata [$feature]) {foreach:: $memberdata [$feature] as $key + = $member) {echo $key. ': ' $member. ' <br> '; }}}}class profession extends member{public static function show () {$feature = Get_called_class (); if (self:: $memberdata [$feature]) {foreach:: $memberdata [$feature] as $key + = $member) {echo $key. ': ' $member. ' <br> '; }}}}user::set_name (' Fdipzone '); User::set_age (29); User::show (); Profession::set_profession (' IT SERVICE '); Profession::set_price (2500); Profession::show ();? >
This article explains about PHP __call and __callstatic content, more relevant knowledge, please pay attention to the PHP Chinese web.
Related recommendations:
About memcached common commands and instructions for use
About phpmailer-php e-mail Transport class
Understanding of PHP Traversal folders and file classes and processing classes