Ask HN: PHP, interfaces, typehinting subtype and LSP?
interface I
{
function foo(stdClass $arg);
}
class Test extends stdClass
{
}
class Implementation implements I
{
function foo(Test $arg)
{
}
}
Result:
Fatal error: Declaration of InterfaceImplementation::foo() must be compatible with I::foo(stdClass $arg) in test.php on line XY
How come that I can't type hint a subtype in the implementation?
6 comments
[ 167 ms ] story [ 1229 ms ] threadAlso NOT available in java.lang.