示例: 界面是
public function doFoo($bar);
我可以有一个类来实现带有方法的接口(interface)
public function doFoo(array $bar = array('test')) { }
PHP 中方法签名的含义是什么?
只是方法名称和参数名称吗? 或者,还包括类型提示和参数默认值?
最佳答案
参数的默认值在接口中并不固定(澄清一下:该值不是固定的,但如果接口(interface)有默认值,那么实现该接口(interface)的类也需要一个默认值,但是值不是由接口(interface)固定的)。
但是,当接口(interface)定义带有类型提示的方法时,该类必须使用相同的类型提示!您还可以在 manual 中看到这一点.
还有来自那里的引用:
An interface, together with type-hinting, provides a good way to make sure that a particular object contains particular methods. See instanceof operator and type hinting.
关于php - 类型提示和默认参数值也是方法签名吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30001977/