Created
November 9, 2016 14:15
-
-
Save brzuchal/8add0fc826410b5cb7c3ed76b9a67fbd to your computer and use it in GitHub Desktop.
Object typehint & return type variance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class A {} | |
class B { | |
function foo(object $a) : object { | |
return $a; | |
} | |
} | |
class C extends B { | |
function foo(A $a) : A { | |
return $a; | |
} | |
} // Fatal error: Declaration of C::foo(A $a): A must be compatible with B::foo(object $a): object in object-variance.php on line 14 | |
$a = new A(); | |
$b = new B(); | |
$b->foo($a); | |
$c = new C(); | |
$c->foo($a); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment