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; public $whoops = "\xc2"; } $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.0110.00719.13
8.5.20.0080.01119.64
8.5.10.0100.01018.57
8.5.00.0150.00620.18
8.4.180.0160.01019.62
8.4.170.0050.00524.00
8.4.160.0130.01123.25
8.4.150.0120.00416.86
8.4.140.0100.01117.70
8.4.130.0060.00317.79
8.4.120.0090.01022.27
8.4.110.0050.00422.50
8.4.100.0140.00618.72
8.4.90.0110.00718.66
8.4.80.0100.01020.74
8.4.70.0100.00518.98
8.4.60.0110.00918.70
8.4.50.0110.00918.90
8.4.40.0030.00717.83
8.4.30.0150.00717.68
8.4.20.0110.01119.45
8.4.10.0060.00319.61
8.3.300.0150.00619.14
8.3.290.0090.01122.63
8.3.280.0080.01418.51
8.3.270.0130.00616.50
8.3.260.0120.00816.52
8.3.250.0090.01019.01
8.3.240.0050.00316.83
8.3.230.0080.01116.49
8.3.220.0050.00218.94
8.3.210.0070.01216.79
8.3.200.0060.00316.48
8.3.190.0030.00519.18
8.3.180.0060.00418.80
8.3.170.0070.01419.21
8.3.160.0040.01118.47
8.3.150.0130.00719.16
8.3.140.0000.00917.02
8.3.130.0000.00818.61
8.3.120.0120.00618.73
8.3.110.0080.01116.75
8.3.100.0100.00624.06
8.3.90.0090.00926.77
8.3.80.0090.00017.97
8.3.70.0040.01616.63
8.3.60.0040.01118.28
8.3.50.0110.00718.25
8.3.40.0080.00818.88
8.3.30.0120.00318.79
8.3.20.0040.00420.29
8.3.10.0000.00821.92
8.3.00.0060.00319.50
8.2.300.0130.01020.55
8.2.290.0120.00720.68
8.2.280.0130.00820.07
8.2.270.0040.01516.45
8.2.260.0040.00417.42
8.2.250.0000.01016.76
8.2.240.0070.01118.91
8.2.230.0170.00320.94
8.2.220.0060.00337.54
8.2.210.0120.00626.77
8.2.200.0030.00618.29
8.2.190.0150.00016.63
8.2.180.0150.00425.92
8.2.170.0110.00318.91
8.2.160.0040.01122.96
8.2.150.0060.00324.18
8.2.140.0080.00024.66
8.2.130.0000.00820.98
8.2.120.0080.00026.35
8.2.110.0030.00620.52
8.2.100.0040.00818.03
8.2.90.0060.00318.03
8.2.80.0000.00819.27
8.2.70.0030.00518.05
8.2.60.0040.00418.05
8.2.50.0030.00518.10
8.2.40.0040.00422.30
8.2.30.0080.00019.51
8.2.20.0070.00018.02
8.2.10.0050.00218.18
8.2.00.0030.00518.38
8.1.340.0110.00917.70
8.1.330.0110.00821.85
8.1.320.0130.00917.79
8.1.310.0030.00516.87
8.1.300.0070.01020.27
8.1.290.0090.00330.84
8.1.280.0130.00325.92
8.1.270.0050.00320.33
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0090.00322.12
8.1.230.0040.00721.00
8.1.220.0050.00317.74
8.1.210.0080.00018.80
8.1.200.0060.00317.35
8.1.190.0050.00317.48
8.1.180.0040.00418.10
8.1.170.0000.00818.50
8.1.160.0040.00418.84
8.1.150.0040.00422.04
8.1.140.0040.00417.67
8.1.130.0000.01118.77
8.1.120.0030.00417.38
8.1.110.0000.00717.44
8.1.100.0040.00417.47
8.1.90.0020.00517.50
8.1.80.0040.00417.54
8.1.70.0040.00417.46
8.1.60.0050.00317.58
8.1.50.0000.00817.50
8.1.40.0040.00417.59
8.1.30.0060.00317.63
8.1.20.0040.00417.61
8.1.10.0040.00717.60
8.1.00.0080.00017.41
8.0.300.0000.00820.07
8.0.290.0060.00316.88
8.0.280.0030.00518.35
8.0.270.0030.00317.24
8.0.260.0070.00016.89
8.0.250.0050.00317.08
8.0.240.0070.00316.97
8.0.230.0050.00316.95
8.0.220.0030.00316.86
8.0.210.0070.00016.91
8.0.200.0030.00316.92
8.0.190.0040.00417.05
8.0.180.0070.00016.98
8.0.170.0030.00616.97
8.0.160.0040.00417.06
8.0.150.0060.00516.81
8.0.140.0000.00716.94
8.0.130.0000.00613.36
8.0.120.0000.00816.92
8.0.110.0000.00717.03
8.0.100.0000.00716.82
8.0.90.0040.00416.88
8.0.80.0120.00416.86
8.0.70.0070.00016.96
8.0.60.0070.00017.02
8.0.50.0050.00216.81
8.0.30.0120.00817.30
8.0.20.0090.01117.40
8.0.10.0080.00017.14
8.0.00.0070.01116.86
7.4.330.0000.00515.55
7.4.320.0060.00016.54
7.4.300.0030.00316.54
7.4.290.0000.00816.44
7.4.280.0030.00616.51
7.4.270.0000.00716.52
7.4.260.0040.00416.67
7.4.250.0070.00016.59
7.4.240.0000.00716.52
7.4.230.0000.00716.59
7.4.220.0050.00216.71
7.4.210.0100.00616.56
7.4.200.0070.00016.72
7.4.160.0150.00416.58
7.4.150.0130.01017.40
7.4.140.0120.00817.86
7.4.130.0100.00716.42
7.4.120.0060.01316.62
7.4.110.0120.00616.53
7.4.100.0130.01016.54
7.4.90.0060.01116.60
7.4.80.0170.00719.39
7.4.70.0120.00616.63
7.4.60.0060.00916.56
7.4.50.0060.00816.64
7.4.40.0130.00316.58
7.4.10.0060.01014.86
7.4.00.0100.00715.16
7.3.330.0000.00513.45
7.3.320.0030.00313.22
7.3.310.0030.00316.48
7.3.300.0070.00016.45
7.3.290.0030.00316.33
7.3.280.0080.01316.47
7.3.270.0130.00617.40
7.3.260.0110.00816.51
7.3.250.0080.01316.45
7.3.240.0090.01016.54
7.3.230.0110.00616.52
7.3.210.0120.00416.52
7.3.200.0060.01116.45
7.3.190.0070.01116.67
7.3.180.0060.01316.56
7.3.170.0080.01316.45
7.3.160.0070.01016.64
7.3.130.0130.00614.67
7.3.120.0070.01114.94
7.3.110.0150.00014.82
7.3.100.0030.01014.82
7.3.90.0170.00314.96
7.3.80.0110.00314.70
7.3.70.0070.01014.80
7.3.60.0000.01314.57
7.3.50.0070.00714.96
7.3.40.0110.00314.89
7.3.30.0080.00815.00
7.3.20.0080.00816.80
7.3.10.0070.00816.64
7.3.00.0070.00616.64
7.2.330.0070.01116.92
7.2.320.0110.01116.78
7.2.310.0130.00316.55
7.2.300.0100.00716.61
7.2.290.0040.01216.93
7.2.260.0060.01215.20
7.2.250.0060.01015.12
7.2.240.0090.00614.81
7.2.230.0030.01314.96
7.2.220.0040.00815.36
7.2.210.0070.01015.28
7.2.200.0070.00715.19
7.2.190.0000.01415.06
7.2.180.0050.00514.91
7.2.170.0070.01015.28
7.2.160.0100.00315.25
7.2.150.0070.00317.02
7.2.140.0000.01516.70
7.2.130.0050.00916.86
7.2.120.0010.01216.95
7.2.110.0080.00417.03
7.2.100.0070.00716.94
7.2.90.0140.00816.44
7.2.80.0130.00616.29
7.2.70.0140.00716.44
7.2.60.0170.00716.55
7.2.50.0150.00716.43
7.2.40.0120.00816.42
7.2.30.0140.00716.49
7.2.20.0130.00816.49
7.2.10.0210.00916.66
7.2.00.0220.00916.73
7.1.330.0090.00715.80
7.1.320.0070.00715.79
7.1.310.0170.00015.79
7.1.300.0060.00915.88
7.1.290.0040.00816.02
7.1.280.0000.01315.76
7.1.270.0030.01015.79
7.1.260.0140.00715.89
7.1.250.0070.00615.89
7.1.240.0070.00715.61
7.1.230.0080.00416.01
7.1.220.0060.00315.80
7.1.210.0260.00814.88
7.1.200.0160.00615.23
7.1.190.0190.00914.89
7.1.180.0210.00314.86
7.1.170.0220.00514.85
7.1.160.0230.01114.95
7.1.150.0270.01014.88
7.1.140.0570.01014.85
7.1.130.0300.01115.32
7.1.120.0350.00615.53
7.1.110.0240.00815.17
7.1.100.0430.01115.31
7.1.90.0320.00815.36
7.1.80.0280.00615.21
7.1.70.0210.01115.19
7.1.60.0420.00626.98
7.1.50.0390.01326.94
7.1.40.0370.01026.65
7.1.30.0440.01126.75
7.1.20.0300.00926.83
7.1.10.0280.00714.67
7.1.00.0240.00814.88
7.0.330.0030.00715.03
7.0.320.0030.00614.97
7.0.310.0050.00515.33
7.0.300.0000.01415.33
7.0.290.0000.01715.22
7.0.280.0000.01215.40
7.0.270.0030.01215.44
7.0.260.0090.00315.10
7.0.250.0030.01015.18
7.0.240.0040.01115.38
7.0.230.0030.01015.45
7.0.220.0000.01115.25
7.0.210.0060.00615.34
7.0.200.0000.01415.30
7.0.190.0000.01015.08
7.0.180.0070.00715.06
7.0.170.0050.00514.98
7.0.160.0070.00715.07
7.0.150.0060.00615.24
7.0.140.0000.01215.20
7.0.130.0030.00915.27
7.0.120.0060.00615.28
7.0.110.0050.00315.18
7.0.100.0030.01215.55
7.0.90.0030.00615.32
7.0.80.0030.01015.33
7.0.70.0070.00315.40
7.0.60.0080.00815.16
7.0.50.0040.00415.43
7.0.40.0040.01113.41
7.0.30.0040.01113.35
7.0.20.0110.00313.24
7.0.10.0060.00313.42
7.0.00.0080.00313.38
5.6.400.0030.00714.32
5.6.390.0110.00314.12
5.6.380.0030.00614.28
5.6.370.0060.00614.09
5.6.360.0060.01014.16
5.6.350.0090.00613.92
5.6.340.0030.00614.31
5.6.330.0030.01014.33
5.6.320.0080.00814.01
5.6.310.0070.00714.01
5.6.300.0000.01314.11
5.6.290.0040.00814.31
5.6.280.0040.01114.29
5.6.270.0090.00014.11
5.6.260.0090.00314.27
5.6.250.0060.00614.35
5.6.240.0070.00714.16
5.6.230.0050.00514.24
5.6.220.0110.00614.03
5.6.210.0080.00614.14
5.6.200.0070.01014.32
5.6.190.0090.00614.46
5.6.180.0100.00314.38
5.6.170.0040.00814.09
5.6.160.0000.01714.04
5.6.150.0030.01014.33
5.6.140.0000.01714.14
5.6.130.0090.00314.23
5.6.120.0060.01014.38
5.6.110.0000.01614.21
5.6.100.0090.00914.20
5.6.90.0060.00914.18
5.6.80.0060.01213.88
5.6.70.0120.00314.16
5.6.60.0080.00614.03
5.6.50.0070.00714.13
5.6.40.0030.01213.90
5.6.30.0030.00914.26
5.6.20.0000.01413.93
5.6.10.0070.00713.88
5.6.00.0070.00714.03

preferences:
94.82 ms | 2054 KiB | 5 Q