Ask HN: PHP, interfaces, typehinting subtype and LSP?

https://news.ycombinator.com/item?id=6834088
by enterx • 13 years ago
2 6 13 years ago

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?

Related Stories

Loading related stories...

Source preview

news.ycombinator.com