December 9, 2015 | In: Programovanie
php7 invariants and signature validation or class return type
Variance and Signature Validation – basically in simple layman’s term – class return type
then interesting thing I find about the example from
class A {} interface SomeInterface { public function test() : A; } class B implements SomeInterface { public function test() : A // all good! { return null; } public function test2() : string { return 'wow'; } } // all good, will not fail $b = new B(); // will fail with TypeError: // Return value of B::test() must be an instance of A, null returned // $b->test(); $b->test2(); // all good
more about php7:
Comments are closed.