run code in 200+ php & hhvm versions
Bugs & Features
<?php class A { protected $foo = 'initial'; public function get():string {return $this->foo; } public function set(string $bar): A {$this->foo = $bar; return $this;} } class B extends A { public function set(string $bar): B {$this->foo = $bar.'!'; return $this;} } $a = new A; $b = new B; $a->set('A'); $b->set('B'); var_dump([$a->get(), $b->get()]);
Output for 7.1.10
Fatal error: Declaration of B::set(string $bar): B must be compatible with A::set(string $bar): A in /in/90tor on line 11
Process exited with code 255.