3v4l.org

run code in 300+ PHP versions simultaneously
<?php function doSerialize($obj) { $data = $obj->__serialize(); // produce a string out of the data array return $data; } function doUnserialize($class, $data) { // $data will contain a string with all information about class, self-references etc $new = (new ReflectionClass($class))->newInstanceWithoutConstructor(); // this happens before calling __unserialize internally for self refferences $data['selfref'] = $new; return $class::__unserialize($new, $data); } class Test { public $prop; public $selfref; function __construct() { $this->prop = 'prop'; $this->selfref = $this; } public function __serialize(): array { return ['prop' => $this->prop]; } public static function __unserialize(self $new, array $data): self { $new->prop = $data['prop']; $new->selfref = $data['selfref']; return $new; } } class Test2 { public $prop; public $selfref; function __construct() { $this->prop = 'prop'; $this->selfref = $this; } public function __serialize(): array { return ['prop' => $this->prop]; } public static function __unserialize(self $new, array $data): self { $new = (new ReflectionClass(self::class))->newInstanceWithoutConstructor(); $new->prop = $data['prop']; $new->selfref = $new; return $new; } } $a1 = new Test; $adata = doSerialize($a1); $a2 = doUnserialize('Test', $adata); var_dump($a2, $a2 === $a2->selfref); $b1 = new Test2; $bdata = doSerialize($b1); $b2 = doUnserialize('Test2', $bdata); var_dump($b2, $b2 === $b2->selfref);

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.60.0120.00318.68
8.3.50.0100.01017.72
8.3.40.0150.00718.71
8.3.30.0090.00618.48
8.3.20.0040.00420.78
8.3.10.0000.00818.66
8.3.00.0000.00822.50
8.2.170.0060.01022.96
8.2.160.0100.00320.37
8.2.150.0040.00424.18
8.2.140.0090.00024.66
8.2.130.0050.00326.16
8.2.120.0040.00420.56
8.2.110.0000.00922.30
8.2.100.0080.00417.78
8.2.90.0040.00717.37
8.2.80.0050.00317.97
8.2.70.0000.00917.80
8.2.60.0080.00017.97
8.2.50.0030.00718.10
8.2.40.0030.00619.30
8.2.30.0000.00719.12
8.2.20.0050.00217.91
8.2.10.0040.00419.38
8.2.00.0000.00817.88
8.1.270.0040.00422.27
8.1.260.0080.00026.35
8.1.250.0080.00028.09
8.1.240.0060.00322.73
8.1.230.0040.00719.15
8.1.220.0040.00417.74
8.1.210.0000.00818.77
8.1.200.0070.00717.23
8.1.190.0060.00317.12
8.1.180.0000.00818.10
8.1.170.0030.00518.43
8.1.160.0000.00718.80
8.1.150.0070.00018.80
8.1.140.0000.00720.29
8.1.130.0030.00320.29
8.1.120.0030.00517.36
8.1.110.0030.00317.43
8.1.100.0040.00417.37
8.1.90.0080.00017.40
8.1.80.0000.00717.30
8.1.70.0030.00317.27
8.1.60.0050.00317.47
8.1.50.0000.00817.47
8.1.40.0000.00717.46
8.1.30.0040.00417.43
8.1.20.0000.00817.45
8.1.10.0040.00417.40
8.1.00.0000.01017.32
8.0.300.0040.00418.77
8.0.290.0090.00316.58
8.0.280.0030.00318.27
8.0.270.0040.00416.80
8.0.260.0030.00318.23
8.0.250.0000.00816.90
8.0.240.0030.00516.80
8.0.230.0100.00016.91
8.0.220.0030.00316.93
8.0.210.0000.00716.87
8.0.200.0000.00716.84
8.0.190.0040.00416.99
8.0.180.0050.00316.86
8.0.170.0030.00516.78
8.0.160.0030.00716.83
8.0.150.0040.00416.85
8.0.140.0000.00716.88
8.0.130.0050.00013.33
8.0.120.0070.00016.84
8.0.110.0050.00316.74
8.0.100.0000.00716.82
8.0.90.0080.00016.86
8.0.80.0140.00016.81
8.0.70.0080.00016.65
8.0.60.0050.00216.70
8.0.50.0070.00016.68
8.0.30.0100.01016.93
8.0.20.0110.00817.00
8.0.10.0040.00416.93
8.0.00.0150.00616.79
7.4.330.0000.00515.55
7.4.320.0060.00016.46
7.4.300.0030.00316.65
7.4.290.0070.00016.65
7.4.280.0050.00316.62
7.4.270.0040.00316.55
7.4.260.0080.00016.53
7.4.250.0000.00716.49
7.4.240.0000.00716.62
7.4.230.0000.00716.45
7.4.220.0000.00816.68
7.4.210.0120.00316.68
7.4.200.0040.00416.63
7.4.160.0090.01016.55
7.4.140.0040.01417.86
7.4.130.0140.00416.69
7.4.120.0130.01016.70
7.4.110.0090.00916.66
7.4.100.0000.01816.70
7.4.90.0090.00916.64
7.4.80.0040.01819.39
7.4.70.0090.01216.54
7.4.60.0060.01816.46
7.4.50.0060.01016.61
7.4.40.0090.01316.52
7.4.10.0090.00915.04
7.4.00.0050.01315.25
7.3.330.0030.00313.22
7.3.320.0000.00513.38
7.3.310.0000.00716.25
7.3.300.0000.00716.42
7.3.290.0070.00016.29
7.3.280.0080.00916.35
7.3.260.0150.00616.56
7.3.240.0100.01016.46
7.3.230.0070.01016.69
7.3.210.0150.00316.44
7.3.200.0030.01316.62
7.3.190.0170.00316.46
7.3.180.0110.00616.50
7.3.170.0140.00316.55
7.3.160.0150.00316.48
7.3.130.0160.00315.07
7.3.120.0140.00315.11
7.3.110.0130.00614.76
7.3.100.0040.01114.83
7.3.90.0060.00315.13
7.3.80.0000.01015.23
7.3.70.0060.00314.82
7.3.60.0030.00915.01
7.3.50.0060.00314.86
7.3.40.0030.00914.71
7.3.30.0030.01414.94
7.3.20.0890.00415.33
7.3.10.0920.00415.38
7.3.00.0790.00815.45
7.2.330.0140.00516.77
7.2.320.0090.01516.69
7.2.310.0030.01216.65
7.2.300.0050.01116.81
7.2.290.0110.00816.55
7.2.260.0060.01315.20
7.2.250.0090.00915.25
7.2.240.0040.01114.92
7.2.230.0030.01015.13
7.2.220.0040.01114.98
7.2.210.0090.00314.98
7.2.200.0040.01115.16
7.2.190.0060.00615.02
7.2.180.0030.01015.14
7.2.170.0030.01215.14
7.2.160.0040.01114.93
7.2.150.0810.00415.68
7.2.140.0700.01115.73
7.2.130.0840.00715.81
7.2.120.0880.00915.67
7.2.110.0840.00415.65
7.2.100.0740.00215.73
7.2.90.0810.01415.71
7.2.80.0790.01215.61
7.2.70.0870.00415.74
7.2.60.0840.00715.63
7.2.50.0960.00415.66
7.2.40.1000.00715.74
7.2.30.1280.00915.61
7.2.20.0800.00615.55
7.2.10.0870.00815.55
7.2.00.0800.00715.69
7.1.330.0030.01015.98
7.1.320.0030.01015.54
7.1.310.0000.01615.97
7.1.300.0030.00715.58
7.1.290.0030.01015.66
7.1.280.0060.00615.67
7.1.270.0080.00015.98
7.1.260.0050.00815.54
7.1.250.1090.00814.39
7.1.240.0090.00315.82
7.1.230.0000.01215.93
7.1.220.0030.00915.88
7.1.210.0090.00615.88
7.1.200.0040.00915.71
7.1.190.0060.01015.79
7.1.180.0090.00915.71
7.1.170.0070.00715.95
7.1.160.0070.01015.86
7.1.150.0100.00315.84
7.1.140.0100.00315.69
7.1.130.0030.00715.82
7.1.120.0000.01315.68
7.1.110.0110.00315.97
7.1.100.0030.00715.73
7.1.90.0000.00815.96
7.1.80.0030.00615.82
7.1.70.0070.00415.98
7.1.60.0090.00615.73
7.1.50.0030.01315.70
7.1.40.0070.01015.89
7.1.30.0060.00615.61
7.1.20.0120.00316.02
7.1.10.0070.00715.75
7.1.00.0090.00616.00

preferences:
93.16 ms | 400 KiB | 5 Q