3v4l.org

run code in 300+ PHP versions simultaneously
<?php $listOfIntegers = [1, 2, 3, 4]; $myObject = new stdClass(); $myObject->integers = $listOfIntegers; echo json_encode($myObject) . PHP_EOL; // Output of the code above will be: `{"integers":[1,2,3,4]}` // Now some refactoring has to be made since the requirement changed. The requirement now is that the integers list // must not contain odd values anymore. So `array_filter` to the rescue, right? $listOfEvenIntegers = array_filter([1, 2, 3, 4], static fn (int $integer): int => $integer % 2 === 0); $myObject = new stdClass(); $myObject->integers = $listOfEvenIntegers; echo json_encode($myObject) . PHP_EOL; // Output of the refactored code above now became: `{"integers":{"1":2,"3":4}}` // So what now happened is a huge problem for highly type-sensitive API clients since we changed a list to a hashmap // Same happens with hashmaps which suddenly become empty. $hashmap = [ 'foo' => 'bar', ]; $myObject = new stdClass(); $myObject->map = $hashmap; echo json_encode($myObject) . PHP_EOL; // Output of the code above will be: `{"map":{"foo":"bar"}}` // So now some properties are being added, some are being removed, the definition of your API says // "the object will contain additional properties because heck I do not want to declare every property" // "so to make it easier, every property has a string value" // can be easily done with something like this in JSONSchema: `{"type": "object", "additional_properties": {"type": "string"}}` // Now, some string value might become `null` due to whatever reason, lets say it was a bug and thus the happy path always returned a string // The most logical way here is, due to our lazyness, to use something like `array_filter` to get rid of all our non-string values $hashmap = [ 'foo' => null, ]; $myObject = new stdClass(); $myObject->map = array_filter($hashmap); echo json_encode($myObject) . PHP_EOL; // Output of the refactored code above now became: `{"map":[]}` // So in case that every array value is being wiped due to the filtering, we suddenly have a type-change from // a hashmap to a list. This is ofc also problematic since we do not want to have a list here but an empty object like // so: `{"map":{}}`

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.3.130.0160.00018.29
8.3.120.0140.00018.84
8.3.110.0130.00620.94
8.3.100.0080.00016.48
8.3.90.0040.00426.77
8.3.80.0040.00718.58
8.3.70.0180.00016.88
8.3.60.0130.00918.56
8.3.50.0110.00420.21
8.3.40.0090.00620.11
8.3.30.0120.00319.18
8.3.20.0040.00424.18
8.3.10.0050.00324.66
8.3.00.0060.00326.16
8.2.250.0130.00316.71
8.2.240.0000.00918.08
8.2.230.0040.00822.58
8.2.220.0090.00024.06
8.2.210.0090.00626.77
8.2.200.0030.00618.41
8.2.190.0120.00416.58
8.2.180.0070.00725.92
8.2.170.0040.01122.96
8.2.160.0070.00722.96
8.2.150.0070.00025.66
8.2.140.0040.00424.66
8.2.130.0070.00026.16
8.2.120.0050.00321.11
8.2.110.0040.00422.18
8.2.100.0060.00320.58
8.1.300.0050.00317.89
8.1.290.0090.00030.84
8.1.280.0100.00725.92
8.1.270.0080.00023.99
8.1.260.0080.00026.35
8.1.250.0000.00728.09
8.1.240.0000.00918.63
8.1.230.0000.00918.45
8.1.60.0090.00417.45

preferences:
42.4 ms | 403 KiB | 5 Q