3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Entity extends PDO { public function __construct() { try { parent::__construct('mysql:host=localhost;dbname=X', 'db_user', 'db_pass'); parent::setAttributes(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $e) { die($e->getMessage()); }} } class DataSource { public static function simple_select($sql, array $values) { $smpt = (new Entity)->Prepare($sql); $smpt->execute($values); return $smpt->fetchAll(); } } class UniqueString { private $Secret; public function __construct($secret) { $this->Secret = $secret; } public function fetch() { return $this->Secret; } } class Generate { private static $Secret; private static $Sql = 'SELECT user_id FROM users WHERE salt = ?'; public static function randomString(int $len) { do { self::$Secret = mcrypt_create_iv($len, MCRYPT_DEV_URANDOM); } while (!empty(DataSource::simple_select(self::$Sql, [self::$Secret])['user_id'])); return new UniqueString(self::$Secret); } } echo Generate::randomString(16)->fetch();
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, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Fatal error: Uncaught Error: Call to undefined function mcrypt_create_iv() in /in/jPCSd:35 Stack trace: #0 /in/jPCSd(41): Generate::randomString(16) #1 {main} thrown in /in/jPCSd on line 35
Process exited with code 255.
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 Fatal error: Uncaught Error: Call to undefined function mcrypt_create_iv() in /in/jPCSd:35 Stack trace: #0 /in/jPCSd(41): Generate::randomString(16) #1 {main} thrown in /in/jPCSd on line 35
Process exited with code 255.
Output for 5.6.0 - 5.6.27
Catchable fatal error: Argument 1 passed to Generate::randomString() must be an instance of int, integer given, called in /in/jPCSd on line 41 and defined in /in/jPCSd on line 34
Process exited with code 255.

preferences:
229.31 ms | 401 KiB | 233 Q