3v4l.org

run code in 300+ PHP versions simultaneously
<?php const KEY_CLASS_NAME = "JSON\\NameSpaceThatAvoidsCollisionsWithFields\\className"; function arrayze($item){ if($item === NULL || is_scalar($item)){ return $item; }elseif(is_object($item)){ $className = get_class($item); $item = (Array)$item; $item[KEY_CLASS_NAME] = $className; } $array = []; foreach($item as $key => $content){ $array[base64_encode($key)] = arrayze($content); } return $array; } function dearrayze($item){ assert(is_object($item) === FALSE); if($item === NULL || is_scalar($item)){ return $item; } $itemClean = []; foreach($item as $key => $content){ $itemClean[base64_decode($key)] = dearrayze($content); } $item = $itemClean; $className = $item[KEY_CLASS_NAME] ?? NULL; if($className !== NULL){ $RC = new ReflectionClass($className); $object = $RC->newInstanceWithoutConstructor(); foreach($item as $property => $content){ if($property === KEY_CLASS_NAME) continue; // 0 ClassName 0 privateProperty // 0 * 0 protectedProperty // publicProperty if(count($p = explode("\0", $property)) === 3){ [$void, $scope, $actualPropertyName] = $p; $scope = $scope === "*" ? $className : $scope; (function() use($actualPropertyName, $content){ $this->{$actualPropertyName} = $content; })->bindTo($object, $scope)(); }else{ $object->{$property} = $content; } } $item = $object; } return $item; } function json_encode_object($object){ $arrayzed = arrayze($object); return json_encode($arrayzed, JSON_PRETTY_PRINT); } function json_decode_object(String $object){ $arrayzed = json_decode($object, TRUE); return dearrayze($arrayzed); } class Father{ public $fpublic = 1; protected $fprotected = 2; private $fprivate = 3; } class Child extends Father{ public $cpublic = 1; protected $cprotected = 2; private $cprivate = 3; } $child = new Child(); var_dump($child); echo "encoded:\n"; $encoded = json_encode_object($child); var_dump($encoded); echo "decoded:\n"; $decoded = json_decode_object($encoded); var_dump($decoded);

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.5.30.0100.00919.21
8.5.20.0120.00719.50
8.5.10.0100.00718.42
8.5.00.0140.00720.04
8.4.180.0130.00919.82
8.4.170.0160.00520.62
8.4.160.0100.01223.32
8.4.150.0080.00416.95
8.4.140.0100.01217.61
8.4.130.0070.00317.76
8.4.120.0090.01120.36
8.4.110.0060.00820.54
8.4.100.0150.00717.71
8.4.90.0050.00418.68
8.4.80.0120.00919.50
8.4.70.0120.00818.04
8.4.60.0150.00617.88
8.4.50.0130.00917.80
8.4.40.0000.00917.82
8.4.30.0170.00317.88
8.4.20.0060.00319.71
8.4.10.0040.00419.47
8.3.300.0100.01220.89
8.3.290.0100.01022.47
8.3.280.0090.01118.66
8.3.270.0130.00716.73
8.3.260.0110.00916.61
8.3.250.0130.00719.03
8.3.240.0120.00716.69
8.3.230.0140.00616.49
8.3.220.0060.00217.17
8.3.210.0100.01116.57
8.3.200.0090.01016.66
8.3.190.0130.00716.65
8.3.180.0110.00718.50
8.3.170.0080.00019.00
8.3.160.0120.00616.57
8.3.150.0070.01420.87
8.3.140.0040.01116.75
8.3.130.0080.00018.50
8.3.120.0030.00620.95
8.3.110.0040.00416.50
8.3.100.0000.00824.06
8.3.90.0030.00626.77
8.3.80.0060.00317.97
8.3.70.0120.00316.48
8.3.60.0070.00718.43
8.3.50.0050.01318.34
8.3.40.0090.00918.79
8.3.30.0060.00918.79
8.3.20.0080.00020.07
8.3.10.0000.00921.85
8.3.00.0040.00419.50
8.2.300.0090.01218.24
8.2.290.0080.01020.67
8.2.280.0120.00818.54
8.2.270.0040.01417.54
8.2.260.0130.00719.03
8.2.250.0040.00417.03
8.2.240.0030.00619.07
8.2.230.0090.00020.94
8.2.220.0030.00637.54
8.2.210.0050.00226.77
8.2.200.0100.00316.75
8.2.190.0090.00916.63
8.2.180.0070.01018.41
8.2.170.0070.00722.96
8.2.160.0110.00719.16
8.2.150.0030.00524.18
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0080.00019.66
8.2.110.0090.00022.28
8.2.100.0120.00017.91
8.2.90.0030.00518.03
8.2.80.0070.00319.27
8.2.70.0080.00017.93
8.2.60.0060.00318.05
8.2.50.0040.00418.14
8.2.40.0000.00820.48
8.2.30.0070.00019.43
8.2.20.0040.00418.14
8.2.10.0040.00418.04
8.2.00.0030.00318.20
8.1.340.0120.00917.63
8.1.330.0030.00522.00
8.1.320.0120.00716.23
8.1.310.0120.00616.76
8.1.300.0120.00318.60
8.1.290.0060.00318.88
8.1.280.0090.00925.92
8.1.270.0040.00420.32
8.1.260.0000.00826.35
8.1.250.0120.00328.09
8.1.240.0030.00622.07
8.1.230.0060.00621.00
8.1.220.0040.00417.79
8.1.210.0000.00918.77
8.1.200.0030.00617.35
8.1.190.0000.00917.35
8.1.180.0050.00318.10
8.1.170.0040.00418.57
8.1.160.0020.00518.90
8.1.150.0040.00422.09
8.1.140.0000.00717.68
8.1.130.0030.00620.67
8.1.120.0050.00217.38
8.1.110.0030.00617.45
8.1.100.0080.00017.37
8.1.90.0030.00517.34
8.1.80.0030.00517.53
8.1.70.0020.00517.52
8.1.60.0040.00417.62
8.1.50.0040.00417.56
8.1.40.0050.00317.56
8.1.30.0060.00317.59
8.1.20.0060.00317.68
8.1.10.0070.00317.46
8.1.00.0000.00817.62
8.0.300.0040.00420.27
8.0.290.0040.00416.75
8.0.280.0030.00318.38
8.0.270.0030.00317.26
8.0.260.0030.00316.89
8.0.250.0030.00316.98
8.0.240.0000.00916.87
8.0.230.0030.00316.93
8.0.220.0070.00016.97
8.0.210.0030.00316.79
8.0.200.0030.00316.95
8.0.190.0040.00417.04
8.0.180.0000.00716.79
8.0.170.0040.00416.83
8.0.160.0040.00416.81
8.0.150.0050.00216.96
8.0.140.0040.00416.89
8.0.130.0000.00613.30
8.0.120.0000.00816.86
8.0.110.0030.00416.99
8.0.100.0040.00416.84
8.0.90.0040.00416.78
8.0.80.0060.01216.93
8.0.70.0000.00717.08
8.0.60.0040.00416.97
8.0.50.0030.00516.85
8.0.30.0090.01017.17
8.0.20.0100.00917.40
8.0.10.0050.00317.10
8.0.00.0110.00716.71
7.4.330.0000.00615.55
7.4.320.0030.00316.59
7.4.300.0030.00316.67
7.4.290.0030.00516.63
7.4.280.0030.00916.57
7.4.270.0000.00716.60
7.4.260.0030.00316.62
7.4.250.0000.00716.44
7.4.240.0070.00016.63
7.4.230.0000.00716.51
7.4.220.0000.00916.64
7.4.210.0090.01116.62
7.4.200.0000.00716.72
7.4.160.0080.01216.57
7.4.150.0100.01017.40
7.4.140.0110.01017.86
7.4.130.0140.00316.53
7.4.120.0100.01116.60
7.4.110.0130.00416.61
7.4.100.0140.01116.46
7.4.90.0110.00816.35
7.4.80.0200.00319.39
7.4.70.0160.00316.66
7.4.60.0100.01316.56
7.4.50.0120.00616.74
7.4.40.0120.00916.45
7.4.00.0060.00914.86
7.3.330.0000.00513.48
7.3.320.0050.00013.31
7.3.310.0070.00016.53
7.3.300.0030.00316.39
7.3.290.0070.00016.49
7.3.280.0090.01316.43
7.3.270.0150.00317.40
7.3.260.0090.01216.41
7.3.250.0090.01216.42
7.3.240.0090.01316.47
7.3.230.0100.00716.59
7.3.210.0070.01016.55
7.3.200.0130.00416.53
7.3.190.0160.00016.52
7.3.180.0000.01716.35
7.3.170.0150.00616.55
7.3.160.0120.01116.57
7.2.330.0120.00816.82
7.2.320.0050.01316.79
7.2.310.0140.00316.88
7.2.300.0060.01016.52
7.2.290.0030.01416.84
7.2.60.0040.00417.04
7.2.10.0260.00717.90
7.2.00.0260.01118.05
7.1.200.0040.00715.88
7.1.130.0210.01117.07
7.1.120.0250.01416.61
7.1.110.0180.01516.25
7.1.100.0260.01016.36
7.1.90.0220.01116.38
7.1.80.0980.01616.32
7.1.70.0240.01415.40
7.1.60.0420.01233.39
7.1.50.0460.01333.02
7.1.40.0260.02032.61
7.1.30.0490.01032.73
7.1.20.0360.01032.97
7.1.10.0300.00714.82
7.1.00.0190.01614.84

preferences:
136.61 ms | 1559 KiB | 5 Q