php类的定义与继承用法实例
本文实例讲述了php类的定义与继承用法。分享给大家供大家参考。具体如下:
<?php /* *class */ classpeople{ public$name; public$age; function__construct($namec,$agec){ $this->name=$namec; $this->age=$agec; } protectedfunctiongetmessage(){ return"姓名:".$this->name."<br/>"."年龄:".$this->age; } function__tostring(){ return"姓名:".$this->name."<br/>"."年龄:".$this->age; } function__destruct(){ echo"<br/>Iamdead!"; } function__call($key,$args){ echo"<br/>","你调用的方法名不存在:$key","<br/>"; echo"你调用的参数是:",var_dump($args); } finalfunctiongetf(){ echo"Iamgetf"; } } classxinxinextendspeople{ functiongetname(){ echo$this->getmessage(); echo'<br/>'; echoparent::getmessage(); echo'<br/>'; return"Iamxinxin"; } functiongetmessage(){ return"Iamzileigetmessage<br/>"; } functiongetff(){ echo"Iamnewgetf"; } } $pp=newpeople("小弟","33"); //$pp->name="小明"; //$pp->age="88"; echo$pp->name; echo''; echo$pp->age; echo'<br/><br/>'; $xx=newxinxin("小小","13"); echo$xx->getname(); ?>
希望本文所述对大家的php程序设计有所帮助。