3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class BaseLevel { public string $name { set => strtolower($value); } abstract public function getName(): string; } class FirstLevel extends BaseLevel { public function getName(): string { return ucfirst($this->name); } } class SecondLevel extends FirstLevel { public function getName(): string { return strtoupper($this->name); } } $firstLevel = new FirstLevel(); $firstLevel->name = 'John'; echo $firstLevel->name; echo $firstLevel->getName(); $secondLevel = new SecondLevel(); # $secondLevel->name = 'Jane'; echo $secondLevel->name; echo $secondLevel->getName();
Output for 8.4.15
johnJohn Fatal error: Uncaught Error: Typed property BaseLevel::$name must not be accessed before initialization in /in/Tnb34:29 Stack trace: #0 {main} thrown in /in/Tnb34 on line 29
Process exited with code 255.

preferences:
153.53 ms | 1002 KiB | 7 Q