3v4l.org

run code in 300+ PHP versions simultaneously
<?php $userJson = '{ "name":"Vasya", "surname":"Popov", "age":33, "address":{ "street":"Pushkina", "house":"Kolotushkina" } }'; $badUserJson = '{ "name":"Vasya", "surname":"Popov", "age":"33", "address":{ "street":"Pushkina", "house":"Kolotushkina" } }'; $noAgeUserJson = '{ "name":"Vasya", "surname":"Popov", "address":{ "street":"Pushkina", "house":"Kolotushkina" } }'; $noAddressUserJson = '{ "name":"Vasya", "surname":"Popov" }'; /** * @property-read string $name * @property-read string $surname * @property-read AddressData $address */ class UserData {} /** * @property-read string $street * @property-read string $house */ class AddressData {} class JsonValidator { protected const IS_STRING = 'static::isString'; protected const IS_INT = 'static::isInt'; protected static $assertions = []; protected static function isString($value) : void { if (false === is_string($value)) { throw new Exception( 'Wrong json value type. Expected: "string" received: "' . gettype($value) . '" value: "' . $value . '"' ); } } protected static function isInt($value) : void { if (false === is_int($value)) { throw new Exception( 'Wrong json value type. Expected: "int" received: "' . gettype($value) . '" value: "' . $value . '"' ); } } public static function validate(object $data): array { $allErrors = []; set_error_handler(static function($errno, $errstr, $errfile, $errline) { throw new ErrorException($errstr, 0, $errno, $errfile, $errline); }); foreach (static::$assertions as $parameterName => $assertionFunction) { try { $parameterValue = $data->$parameterName; $errors = call_user_func($assertionFunction, $parameterValue); } catch (Throwable $exception) { $allErrors[$parameterName][] = $exception->getMessage(); } if (isset($errors) && count($errors)) { $allErrors[$parameterName] = $errors; } } restore_error_handler(); return $allErrors; } } class UserDataValidator extends JsonValidator { private const IS_ADDRESS = 'AddressDataValidator::validate'; protected static $assertions = [ 'name' => self::IS_STRING, 'surname' => self::IS_STRING, 'age' => self::IS_INT, 'address' => self::IS_ADDRESS, ]; } class AddressDataValidator extends JsonValidator { protected static $assertions = [ 'street' => self::IS_STRING, 'house' => self::IS_STRING, ]; } /** @var UserData $userData */ $userData = json_decode($userJson, false); var_dump($userData); $errors = UserDataValidator::validate($userData); print_r($errors); /** @var UserData $userData */ $userData = json_decode($badUserJson, false); var_dump($userData); $errors = UserDataValidator::validate($userData); print_r($errors); /** @var UserData $userData */ $userData = json_decode($noAgeUserJson, false); var_dump($userData); $errors = UserDataValidator::validate($userData); print_r($errors); /** @var UserData $userData */ $userData = json_decode($noAddressUserJson, false); var_dump($userData); $errors = UserDataValidator::validate($userData); print_r($errors);

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.4.130.0160.00717.88
8.4.120.0140.00720.73
8.4.110.0130.01022.43
8.4.100.0150.00817.89
8.4.90.0160.00718.79
8.4.80.0110.01118.08
8.4.70.0110.01117.91
8.4.60.0140.00818.77
8.4.50.0110.01118.09
8.4.40.0140.00723.96
8.4.30.0050.00420.44
8.4.20.0030.00620.84
8.4.10.0090.00024.05
8.3.260.0130.00716.63
8.3.250.0100.00718.65
8.3.240.0130.00716.68
8.3.230.0060.00516.64
8.3.220.0060.00217.28
8.3.210.0130.01016.61
8.3.200.0050.00516.69
8.3.190.0130.00816.96
8.3.180.0100.01016.71
8.3.170.0130.00617.12
8.3.160.0120.00619.10
8.3.150.0110.01117.27
8.3.140.0032.00017.25
8.3.130.0031.99918.14
8.3.120.0131.98918.69
8.3.110.0002.00320.94
8.3.100.0101.99324.06
8.3.90.0031.99826.77
8.3.80.0071.99718.40
8.3.70.0071.99516.48
8.3.60.0032.00116.75
8.3.50.0131.98816.63
8.3.40.0071.99521.78
8.3.30.0101.99518.75
8.3.20.0071.99424.18
8.3.10.0131.98824.66
8.3.00.0101.99326.16
8.2.290.0130.00820.46
8.2.280.0040.00520.14
8.2.270.0060.01318.66
8.2.260.0031.99920.73
8.2.250.0032.00416.54
8.2.240.0032.00617.37
8.2.230.0071.99622.58
8.2.220.0031.99937.54
8.2.210.0002.00426.77
8.2.200.0032.00016.88
8.2.190.0101.99616.58
8.2.180.0131.99118.29
8.2.170.0101.99319.03
8.2.160.0131.98822.96
8.2.150.0071.99425.66
8.2.140.0032.00024.66
8.2.130.0071.99626.16
8.2.120.0031.99821.00
8.2.110.0101.99417.93
8.2.100.0032.00017.78
8.2.90.0002.00217.63
8.2.80.0002.00218.95
8.2.70.0031.99917.48
8.2.60.0071.99617.75
8.2.50.0002.00317.80
8.2.40.0031.99917.75
8.2.30.0002.01517.59
8.2.20.0071.99719.48
8.2.10.0071.99817.59
8.2.00.0301.95617.63
8.1.330.0130.00620.53
8.1.320.0100.00918.25
8.1.310.0130.00616.68
8.1.300.0030.00617.90
8.1.290.0060.00330.84
8.1.280.0100.00625.92
8.1.270.0050.00324.66
8.1.260.0060.00926.35
8.1.250.0040.00428.09
8.1.240.0100.00023.88
8.1.230.0080.00420.98
8.1.220.0030.00617.74
8.1.210.0080.00018.77
8.1.200.0060.00317.66
8.1.190.0030.00517.22
8.1.180.0030.00518.10
8.1.170.0030.00617.62
8.1.160.0130.00317.59
8.1.150.0140.00217.59
8.1.140.0060.01117.59
8.1.130.0060.01017.59
8.1.120.0070.01017.59
8.1.110.0120.00417.59
8.1.100.0160.00017.59
8.1.90.0150.00017.59
8.1.80.0150.00317.59
8.1.70.0130.00417.59
8.1.60.0090.00917.59
8.1.50.0190.00017.59
8.1.40.0180.00017.59
8.1.30.0140.00317.59
8.1.20.0180.00017.60
8.1.10.0110.00717.59
8.1.00.0130.00417.59
8.0.300.0040.00418.77
8.0.290.0080.00016.75
8.0.280.0130.00317.59
8.0.270.0130.00417.59
8.0.260.0160.00017.59
8.0.250.0080.00817.59
8.0.240.0160.00017.59
8.0.230.0160.00017.59
8.0.220.0110.00617.59
8.0.210.0120.00417.59
8.0.200.0050.01117.59
8.0.190.0110.00417.59
8.0.180.0080.00817.59
8.0.170.0110.00417.59
8.0.160.0150.00417.59
8.0.150.0190.00017.59
8.0.140.0120.00417.59
8.0.130.0060.01017.59
8.0.120.0120.00417.59
8.0.110.0120.00417.59
8.0.100.0080.00817.59
8.0.90.0150.00317.59
8.0.80.0130.00417.59
8.0.70.0110.00517.59
8.0.60.0160.00617.59
8.0.50.0080.00817.59
8.0.30.0140.00217.59
8.0.20.0100.00617.59
8.0.10.0000.01617.59
7.4.330.0090.00017.59

preferences:
27.72 ms | 403 KiB | 5 Q