PHP中的参数签名是什么?
发布时间:2020-12-13 17:16:18 所属栏目:PHP教程 来源:网络整理
导读:PHP官方文档在解释有关类和对象部分的扩展时,它说: "When overriding methods,the parameter signature should remain the same or PHPwill generate an E_STRICT level error. This does not apply to the constructorwhich allows overriding with differ
PHP官方文档在解释有关类和对象部分的扩展时,它说:
"When overriding methods,the parameter signature should remain the same or PHP will generate an E_STRICT level error. This does not apply to the constructor which allows overriding with different parameters." 所以我想知道,参数签名是什么? 文档中的示例如下: <?php class ExtendClass extends SimpleClass { // Redefine the parent method function displayVar() { echo "Extending classn"; parent::displayVar(); } } $extended = new ExtendClass(); $extended->displayVar(); ?> 官方在线link 解决方法
参数签名只是方法定义(签名)中参数的定义.引用文本的含义是,在覆盖父类的方法时,使用与参数相同的数字(和类型,在PHP中不适用).
函数/方法的签名也称为头部.它包含名称和参数.函数的实际代码称为body. function foo($arg1,$arg2) // signature { // body } 因此,例如,如果在父类中有方法foo($arg1,$arg2),则不能通过定义方法foo($arg)在扩展类中覆盖它. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |