<?php header("Content-Type:text/html;charset=utf-8"); class People{ public $iq = 100; public function Sayhello(){//打招呼 $say = array("good morning","good noon","good evening"); if($this->iq >= 100){//智商大于等于100 goodmorning echo $say[0]; }else{ $i = rand(0,2);//随机 echo $say[$i]; } } } class Car{ public function Hitme($people){ //撞了下 $iqs = rand(50,110);//智商随你在50-100. $people -> iq = $iqs;//赋给传过来的人!!! } } $ming = new People();//生成人 $BMW = new Car();//生成汽车 $BMW -> Hitme($ming);//宝马撞了小明 $ming -> sayhello(); $BMW -> Hitme($ming); $ming -> sayhello(); $BMW -> Hitme($ming); $ming -> sayhello();