<?php class ourself{ //定义自己人类 private $birthday='1990-12-20'; //定义private修饰的成员属性 public function say_birthday($obj){ //定义一个成员方法 if($obj instanceof ourself){ //判断传入的参数是否为ourself类的对象 echo '我的生日是'.$this->birthday; }else{ echo '我不能告诉你我的生日。'; } } } class other{ //定义一个其他人类 } $tom=new ourself(); //实例化自己人类的对象 $jim=new ourself(); //实例化自己人类的对象 $ken=new other(); //实例化其他人类的对象 echo 'jim想知道tom的生日:'; $tom->say_birthday($jim); //调用成员方法并将相同类的对象jim做为参数 echo '<br />ken想知道tom的生日:'; $tom->say_birthday($ken); //调用成员方法并将不同类的对象ken做为参数 ?>