The__calland__callStaticmagic methods were added after php 5.3.
__callWhen the method to be called does not exist or has insufficient permissions, the __call method will be automatically called.
__callStaticWhen the called static method does not exist or has insufficient permissions, the __callStatic method will be automatically called.
__call($funcname, $arguments)
##__callStatic($funcname, $arguments)
Parameter description:
##$funcnameString The name of the method to be called.
$argumentsArray Parameters taken when calling the method.
__call example
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){ foreach($this->memberdata as $key=>$member){ echo $key.':'.$member.'
'; } } } } class Profession extends Member{ public function show(){ if($this->memberdata){ foreach($this->memberdata as $key=>$member){ echo $key.':'.$member.'
'; } } } } $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(); ?>
__callStatic example
$member){ echo $key.':'.$member.'
'; } } } } class Profession extends Member{ public static function show(){ $feature = get_called_class(); if(self::$memberdata[$feature]){ foreach(self::$memberdata[$feature] as $key=>$member){ echo $key.':'.$member.'
'; } } } } User::set_name('fdipzone'); User::set_age(29); User::show(); Profession::set_profession('IT SERVICE'); Profession::set_price(2500); Profession::show(); ?>
Related recommendations:
About memcached common commands and usage instructions Related explanations about PHPMailer - PHP email transport class Understanding of PHP traversal of folders, file classes and processing classesThe above is the detailed content of Explanation of php __call and __callStatic. For more information, please follow other related articles on the PHP Chinese website!