问题描述
我正在用相同的方法名称在PHP中创建2个接口,并在派生类上实现它。那么,我如何知道正在使用哪个接口?
<?PHP
interface car{
public function intro();
public function carName():string;
}
interface car2{
public function intro();
public function carName():string;
}
class price{
protected $volvo="$50000";
protected $audi="$86000";
protected $buggati="$960000";
protected $tata="$7000";
}
class model extends price implements car,car2{
public $name;
public $price="None";
function __construct($n){
$this->name=$n;
}
public function intro(){
print"Welcome to the ".$this->name."'s showroom.<br>";
}
public function carName():string{
if ($this->name=="Volvo"){
$this->price=$this->volvo;
}
return $this->name."'s car starting price - ".$this->price;
}
}
$ob=new model("Volvo");
$ob->intro();
echo $ob->carName()."<br>";
?>
解决方法
Reflection::export(new ReflectionClass('model'));
有关该类及其功能的完整信息
Class [ <user> class model extends price implements car,car2 ] {
@@ C:\index.php 16-31
- Constants [0] {
}
- Static properties [0] {
}
- Static methods [0] {
}
- Properties [6] {
Property [ <default> public $name ]
Property [ <default> public $price ]
Property [ <default> protected $volvo ]
Property [ <default> protected $audi ]
Property [ <default> protected $buggati ]
Property [ <default> protected $tata ]
}
- Methods [3] {
Method [ <user,ctor> public method __construct ] {
@@ C:\index.php 19 - 21
- Parameters [1] {
Parameter #0 [ <required> $n ]
}
}
Method [ <user,prototype car2> public method intro ] {
@@ C:\index.php 22 - 24
}
Method [ <user,prototype car2> public method carName ] {
@@ C:\index.php 25 - 30
- Parameters [0] {
}
- Return [ string ]
}
}
}