3v4l.org

run code in 300+ PHP versions simultaneously
<?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()]);

preferences:
54.13 ms | 402 KiB | 5 Q