实现具有相同方法名称但签名不同的两个接口(Implementing two interfaces with same method names but different signatures)

系统教程 行业动态 更新时间:2024-06-14 16:57:17
实现具有相同方法名称但签名不同的两个接口(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

更多推荐

本文发布于:2023-04-12 20:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/6e24b7af92c90779bb59e5971dd01ffd.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:接口   名称   两个   方法   Implementing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!