3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Bear { private $age = 0; public function setAge($age) { if ($age < 0) { throw new Exception('Bear cannot have negative age dumbass'); } $this->age = $age; } public function getAge() { return $this->age; } } class BlackBear { private $name; public function setNameAndAge($name, $age) { $this->name = $name; $this->setAge($age); } } $bear1 = new Bear(); $bear1->setAge(35); $bear2 = new BlackBear(); $bear2->setNameAndAge('Harry', 45); var_dump($bear1->getAge()); var_dump($bear2->getAge());
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Call to undefined method BlackBear::setAge() in /in/0CK9i:28 Stack trace: #0 /in/0CK9i(37): BlackBear->setNameAndAge('Harry', 45) #1 {main} thrown in /in/0CK9i on line 28
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Fatal error: Call to undefined method BlackBear::setAge() in /in/0CK9i on line 28
Process exited with code 255.

preferences:
161.86 ms | 402 KiB | 198 Q