实现具有相同方法名称但签名不同的两个接口(Implementing two interfaces with same method names but different signatures)
我有两个具有相同方法名称的接口。 但是,这两种方法都有不同的签名。 根据我的信息,具有相同方法名称和相同签名的两个接口将不起作用。 但是,在这种情况下,签名(即参数的数量)是不同的。 那为什么程序不起作用?
<?php interface Car { public function setModel($name); } interface Vehicle { public function setModel(); } class miniCar implements Car, Vehicle { private $model; public function setModel($name) { $this -> model = $name; } public function setModel() { echo 'do nothing'; } } $obj = new miniCar(); ?>I have two interfaces with same method names. But, both the methods have different signatures. As per my information two interfaces with same method names and same signature will not work. But, in this case signature ( that is number of arguments) are different. Then why program is not working ?
<?php interface Car { public function setModel($name); } interface Vehicle { public function setModel(); } class miniCar implements Car, Vehicle { private $model; public function setModel($name) { $this -> model = $name; } public function setModel() { echo 'do nothing'; } } $obj = new miniCar(); ?>最满意答案
PHP函数不能重载。 他们必须有不同的名字。
PHP函数重载
PHP functions cannot be overloaded. They must have different names.
PHP function overloading
更多推荐
发布评论