<?php
interface Foo {
public function doSomething(string $param1);
}
class Bar implements Foo {
public function doSomething(string $param1) {
echo "Bar: " . $param1;
}
}
class Baz implements Foo {
// Using a named parameter different from Foo's signature
public function doSomething(string $paramName) {
echo "Baz: " . $paramName;
}
}
function processFoo(Foo $foo) {
$foo->doSomething(param1: "Test");
}
$bar = new Bar();
$baz = new Baz();
processFoo($bar); // Works fine
processFoo($baz); // Fatal error:
Bar: Test
Fatal error: Uncaught Error: Unknown named parameter $param1 in /in/L1Ki3:21
Stack trace:
#0 /in/L1Ki3(28): processFoo(Object(Baz))
#1 {main}
thrown in /in/L1Ki3 on line 21
Process exited with code 255.
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Parse error: syntax error, unexpected ':', expecting ')' in /in/L1Ki3 on line 21
Process exited with code 255.