3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); // Would also need the same code for BaseError abstract class BaseException extends Exception { private static $codeReflection; private function setCode(string $code) { if (!isset(self::$codeReflection)) { self::$codeReflection = new ReflectionProperty(self::class, 'code'); self::$codeReflection->setAccessible(true); } self::$codeReflection->setValue($this, $code); } public function __construct(string $message, string $code, \Throwable $previous = null) { parent::__construct($message, 0, $previous); $this->setCode($code); } } class DivisionByZeroException extends BaseException {} $e = new DivisionByZeroException("Test", 'Test001'); var_dump($e->getMessage(), $e->getCode());

preferences:
25.79 ms | 402 KiB | 5 Q