3v4l.org

run code in 300+ PHP versions simultaneously
<?php function setPrevious(Throwable $e, Throwable $previous): Throwable { $reflection = new ReflectionClass($e); $prop = $reflection->getProperty('previous'); $prop->setAccessible(true); $prop->setValue($e, $previous); return $e; } class SimpleException extends Exception { public function __construct($message) { parent::__construct($message); } } $a = new SimpleException('A'); $b = new SimpleException('B'); $c = new SimpleException('C'); setPrevious($a, $b); setPrevious($a, $c); $e = $a; do { var_dump($e->getMessage()); } while ($e = $e->getPrevious());
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
Fatal error: Uncaught ReflectionException: Property SimpleException::$previous does not exist in /in/0ct5l:6 Stack trace: #0 /in/0ct5l(6): ReflectionClass->getProperty('previous') #1 /in/0ct5l(24): setPrevious(Object(SimpleException), Object(SimpleException)) #2 {main} thrown in /in/0ct5l on line 6
Process exited with code 255.
Output for 7.1.26 - 7.1.33, 7.2.17 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Fatal error: Uncaught ReflectionException: Property previous does not exist in /in/0ct5l:6 Stack trace: #0 /in/0ct5l(6): ReflectionClass->getProperty('previous') #1 /in/0ct5l(24): setPrevious(Object(SimpleException), Object(SimpleException)) #2 {main} thrown in /in/0ct5l on line 6
Process exited with code 255.

preferences:
119.38 ms | 408 KiB | 5 Q