3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Yoba { private int $age; public function getAge () : int { return $this->age; } public function setAge (int $age) : void { if (!$this->ageIsValid($age)) { throw new Exception("0 < \$age <= 100, passed " . $age); } $this->age = $age; } public function ageIsValid (int $age) : bool { if (($age > 0) && ($age <= 100)) { return true; } return false; } } $yo = new Yoba(); $yo->setAge(10); echo $yo->getAge(); $yo->setAge(1000); echo $yo->getAge();
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
10 Fatal error: Uncaught Exception: 0 < $age <= 100, passed 1000 in /in/7ldLa:12 Stack trace: #0 /in/7ldLa(28): Yoba->setAge(1000) #1 {main} thrown in /in/7ldLa on line 12
Process exited with code 255.

preferences:
60.16 ms | 406 KiB | 5 Q