Reputation: 4798
The PHP official documentation while explaining about extends under classes and objects section, it says:
"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."
So I want to know, what a parameter signature is?
The example inside the documentation is the following:
<?php
class ExtendClass extends SimpleClass
{
// Redefine the parent method
function displayVar()
{
echo "Extending class\n";
parent::displayVar();
}
}
$extended = new ExtendClass();
$extended->displayVar();
?>
Official online link
Upvotes: 8
Views: 10262
Reputation: 6968
The parameter signature is simply the definition of parameters in the definition (signature) of a method. What is meant with the quoted text is, to use the same number (and type, which is not applicable in PHP) of parameter when overriding a method of a parent class.
A signature of a function/method is also referred to as a head. It contains the name and the parameters. The actual code of the function is called body.
function foo($arg1, $arg2) // signature
{
// body
}
So for example if you have a method foo($arg1, $arg2)
in a parent class, you can't override it in a extended class by defining a method foo($arg)
.
Upvotes: 9