function <functionName> ([<type> ]...<$paramName>) {}
例如:
function someVariadricFunc(...$arguments) {
foreach ($arguments as $arg) {
// do some stuff with $arg...
}
}
someVariadricFunc(); // an empty array going to be passed
someVariadricFunc('apple'); // provides a one-element array
someVariadricFunc('apple', 'pear', 'orange', 'banana');
func(null); //as nullable parameter
func(new Object()); // as parameter of declared type
但是对于可选值签名应该是这样的。
function func(Object $object = null) {} // In case of objects
function func(?Object $object = null) {} // or the same with nullable parameter
function func(string $object = '') {} // In case of scalar type - string, with string value as default value
function func(string $object = null) {} // In case of scalar type - string, with null as default value
function func(?string $object = '') {} // or the same with nullable parameter
function func(int $object = 0) {} // In case of scalar type - integer, with integer value as default value
function func(int $object = null) {} // In case of scalar type - integer, with null as default value
function func(?int $object = 0) {} // or the same with nullable parameter
它可以被调用为
func(); // as optional parameter
func(null); // as nullable parameter
func(new Object()); // as parameter of declared type