相关代码 |
|
4-7-3.php instanceof运算符. class User{ private $name; public function getName(){ return "UserName is ".$this->name; } } class NormalUser extends User { private $age = 99; public function getAge(){ return "age is ".$this->age; } } class UserAdmin{ //操作. public static function getUserInfo(User $_user){ if($_user instanceof NormalUser ){ echo $_user->getAge(); }else{ echo "类型不对,不能使用这个方法."; } } } $User = new User(); // 这里new的是User. UserAdmin::getUserInfo($User); ?>
相关资源 |
|