dreamer2014520 2015-05-02 11:54 采纳率: 0%
浏览 5
已采纳

类型提示和默认参数值是否也是方法签名?

Example : The interface is

public function doFoo($bar);

Can I have a class implementing the interface with method

public function doFoo(array $bar = array('test')) { }

What does the method signature mean in PHP?

Is it just the method name and parameter name ? Or, type hinting and default values for parameters also included ?

  • 写回答

2条回答 默认 最新

  • drk7700 2015-05-02 12:01
    关注

    The default value for an argument isn't fixed with a interface (To clarify: The value isn't fixed, but if the interface has a default value then the class which implements the interface also needs a default value, but the value is not fixed by the interface).

    However when an interface defines a method with a type hint the class must use the same type hint! You can also see this in the manual.

    And a quote from there:

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看