PHP官方文档同时解释了一下extends在类和对象部分下,它说:
"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."
所以我想知道,参数签名是什么?
The example文档内部内容如下:
<?php
class ExtendClass extends SimpleClass
{
// Redefine the parent method
function displayVar()
{
echo "Extending class\n";
parent::displayVar();
}
}
$extended = new ExtendClass();
$extended->displayVar();
?>
官方上线link http://php.net/manual/en/language.oop5.basic.php
参数签名只是方法的定义(签名)中参数的定义。引用文本的意思是,在重写父类的方法时使用相同数量(和类型,这在 PHP 中不适用)的参数。
函数/方法的签名也称为head。它包含名称和参数。该函数的实际代码被调用body.
function foo($arg1, $arg2) // signature
{
// body
}
例如,如果你有一个方法foo($arg1, $arg2)
在父类中,您不能通过定义方法在扩展类中重写它foo($arg)
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)