微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

用相同的方法名称在php中创建2个接口,并在派生类上实现

如何解决用相同的方法名称在php中创建2个接口,并在派生类上实现

我正在用相同的方法名称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 ]
    }
  }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。