3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * A polyfill library with PHP 7's improved way of doing integer division * * @author Michael Cullum <m@michaelcullum.com> * @license http://www.opensource.org/licenses/mit-license.html MIT License * @copyright 2015 Michael Cullum */ namespace { if (!function_exists('intdiv')) { function intdiv($dividend, $divisor) { $dividend = (int) $dividend; $divisor = (int) $divisor; if ($divisor === 0) { throw new DivisionByZeroError('Division by zero'); } if ($divisor === -1 && $dividend == ~PHP_INT_MAX) { throw new ArithmeticError('Division of PHP_INT_MIN by -1 is not an integer'); } $dividend = ($dividend - $dividend % $divisor); return ((int) ($dividend / $divisor)); } } if (!class_exists('ArithmeticError') || !class_exists('DivisionByZeroError')) { if (!class_exists('Throwable')) { class Throwable extends \Exception { public function __toString() { return $this->getMessage(); } } } if (!class_exists('Error')) { class Error extends Throwable { public function __toString() { return $this->getMessage(); } } } if (!class_exists('ArithmeticError')) { class ArithmeticError extends Error { public function __toString() { return $this->getMessage(); } } } if (!class_exists('DivisionByZeroError')) { class DivisionByZeroError extends Error { public function __toString() { return $this->getMessage(); } } } } foreach (array('Error', 'ArithmeticError', 'DivisionByZeroError') as $class) { print_r(class_implements($class)); if (!count(array_intersect(array('Exception', 'Throwable'), class_implements($class)))) { throw new \RuntimeException('A class named \''.$class.'\' is already defined that cannot be thrown.'); } } }
Output for 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Array ( [Stringable] => Stringable [Throwable] => Throwable ) Array ( [Throwable] => Throwable [Stringable] => Stringable ) Array ( [Stringable] => Stringable [Throwable] => Throwable )
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Array ( [Stringable] => Stringable [Throwable] => Throwable ) Array ( [Throwable] => Throwable [Stringable] => Stringable ) Array ( [Stringable] => Stringable [Throwable] => Throwable )
Output for 8.0.0 - 8.0.13
Array ( [Throwable] => Throwable [Stringable] => Stringable ) Array ( [Stringable] => Stringable [Throwable] => Throwable ) Array ( [Throwable] => Throwable [Stringable] => Stringable )
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Array ( [Throwable] => Throwable ) Array ( [Throwable] => Throwable ) Array ( [Throwable] => Throwable )
Output for 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Array ( ) Fatal error: Uncaught exception 'RuntimeException' with message 'A class named 'Error' is already defined that cannot be thrown.' in /in/rZLLA:66 Stack trace: #0 {main} thrown in /in/rZLLA on line 66
Process exited with code 255.

preferences:
194.57 ms | 402 KiB | 258 Q