gpt4 book ai didi

php - 什么是 PHP 中的参数签名?

转载 作者:可可西里 更新时间:2023-10-31 22:44:45 24 4
gpt4 key购买 nike

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 class\n";
parent::displayVar();
}
}

$extended = new ExtendClass();
$extended->displayVar();
?>

官网link

最佳答案

参数签名简单来说就是在一个方法的定义(签名)中对参数的定义。引用文本的意思是,在覆盖父类的方法时使用相同数量(和类型,这在 PHP 中不适用)的参数。
函数/方法的签名也称为 head。它包含名称和参数。该函数的实际代码称为主体

function foo($arg1, $arg2) // signature
{
// body
}

因此,例如,如果您在父类中有方法 foo($arg1, $arg2),则不能通过定义方法 foo( $arg).

关于php - 什么是 PHP 中的参数签名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16219888/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com