本文實例講述了php類的定義與繼承用法。分享給大家供大家參考。具體如下:
<?php /* * class */ class people { public $name; public $age; function __construct($namec,$agec) { $this->name = $namec; $this->age = $agec; } protected function getmessage() { return "姓名:".$this->name."<br/>"."年齡:".$this->age; } function __tostring() { return "姓名:".$this->name."<br/>"."年齡:".$this->age; } function __destruct() { echo "<br/> I am dead!"; } function __call($key,$args) { echo "<br/>","你調用的方法名不存在:$key","<br/>"; echo "你調用的參數是:",var_dump($args); } final function getf() { echo "I am getf"; } } class xinxin extends people { function getname() { echo $this->getmessage(); echo '<br/>'; echo parent::getmessage(); echo '<br/>'; return "I am xinxin"; } function getmessage() { return "I am zilei getmessage <br/>"; } function getff() { echo "I am new getf"; } } $pp = new people("小弟","33"); //$pp->name = "小明"; //$pp->age = "88"; echo $pp->name; echo ' '; echo $pp->age; echo '<br/><br/>'; $xx = new xinxin("小小","13"); echo $xx->getname(); ?>
希望本文所述對大家的php程序設計有所幫助。