The __call and __callStatic magic methods were added after php 5.3.
__call When the method to be called does not exist or has insufficient permissions, the __call method will be automatically called.
__callStatic When 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:
##$funcname String The name of the method to be called.
$arguments Array Parameters taken when calling the method.
__call examplememberdata[$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 instructionsRelated explanations about PHPMailer - PHP email transport classUnderstanding 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!