3v4l.org

run code in 300+ PHP versions simultaneously
<?php readonly class Address { public function __construct( public string $street, public string $city, public string $state, public string $country, public string $postalCode, ){ } } readonly class Person { public function __construct( public string $name, public int $age, public Address $address, ){ } } $bob = new Person('Bob', 32, new Address('123 Main St', 'Testington', 'Test', 'Test', '12345')); $bobJson = json_encode($bob); $decodedBob = json_decode_class($bobJson, Person::class); if ($bob == $decodedBob){ echo 'These are the same person!', PHP_EOL; } else { echo 'We have different people here!', PHP_EOL; } function json_decode_class(string $json, string $class){ return construct_object(json_decode($json), $class); } function construct_object(stdClass $data, string $class){ $rc = new ReflectionClass($class); $properties = $rc->getConstructor()->getParameters(); $constructorArgs = []; foreach ($properties as $prop){ $type = $prop->getType(); if (property_exists($data, $prop->getName())){ $value = $data->{$prop->getName()}; if (!$type->isBuiltin()){ $value = construct_object($value, $type->getName()); } $constructorArgs[$prop->getName()] = $value; } } return $rc->newInstanceArgs($constructorArgs); }

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.120.0140.00620.57
8.4.110.0090.01222.51
8.4.100.0120.00917.78
8.4.90.0100.00818.70
8.4.80.0150.00717.89
8.4.70.0160.00417.80
8.4.60.0110.00418.73
8.4.50.0110.01018.91
8.4.40.0100.01017.48
8.4.30.0030.01720.68
8.4.20.0060.00917.69
8.4.10.0060.00319.46
8.3.250.0090.00918.73
8.3.240.0100.01116.72
8.3.230.0100.01016.64
8.3.220.0110.00617.38
8.3.210.0060.01218.41
8.3.200.0060.00316.51
8.3.190.0130.00518.68
8.3.180.0110.00816.66
8.3.170.0180.00017.16
8.3.160.0110.00318.25
8.3.150.0060.01021.00
8.3.140.0120.00616.66
8.3.130.0060.00318.22
8.3.120.0060.00318.46
8.3.110.0050.00318.71
8.3.50.0060.01316.58
8.2.290.0130.00622.07
8.2.280.0110.00518.40
8.2.270.0100.01017.04
8.2.260.0190.00018.90
8.2.250.0130.00616.55
8.2.240.0110.00716.55
8.2.230.0170.00316.77
8.2.100.0160.00618.66
8.1.330.0110.00821.68
8.1.320.0090.00516.20
8.1.310.0070.00716.79
8.1.300.0150.00415.94

preferences:
26.97 ms | 403 KiB | 5 Q