<?php
class mohona{
public $name;
public $age;
public $fname;
public $lname;
public function __construct($cname,$cage,$cfname,$clname){
$this->name=$cname;
$this->age=$cage;
$this->fname=$cfname;
$this->lname=$clname;
}
public function getMohona(){
echo "Full Name: ".$this->fname." ".$this->lname." ".$this->name."<br/>Age: ".$this->age."<br/>";
}
}
class ibrahim extends mohona{
public $relational_status;
public $relation;
public $contact;
public function __construct($cname,$cage,$cfname,$clname,$crelational_status,$crelation,$ccontact){
parent::__construct($cname,$cage,$cfname,$clname);
$this->relational_status=$crelational_status;
$this->relation=$crelation;
$this->contact=$ccontact;
}
public function getIbrahim(){
echo "Full Name: ".$this->fname." ".$this->lname." ".$this->name."<br/>Age: ".$this->age."<br/>"."Relational Status: ".$this->relational_status."<br/>Maritual Status: ".$this->relation."<br/>Contact Status: ".$this->contact;
}
}
$oMohona=new mohona("Mohona","20","Nafis","Anjum");
$oIbrahim=new ibrahim("Ibu","25","Ibrahim","Akbar","Single","Unmarried","blocked");
echo $oMohona->getMohona();
echo $oIbrahim->getIbrahim();
?>
套装在构造函数中使用特定的数据库凭证通常是一个坏主意。如果你真的需要将数据库凭证连接到一个类中,你应该创建一个工厂方法,比如静态的fn create(){return new self('localhost',...); } – amik 2015-10-22 13:08:04