ThecallandcallStaticmagic 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:
##$funcnameStringCall method name.
$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(); ?>
The above is the detailed content of Detailed explanation of the usage and difference between __call and __callStatic in php. For more information, please follow other related articles on the PHP Chinese website!