3v4l.org

run code in 300+ PHP versions simultaneously
<?php function hashcode($str){ // return sha1($str); return $str; } class SomethingBuilder { private $name; private $super; function __construct($name){ $this->name = $name; } function getName(){ return $this->name; } function setSuper(SomethingBuilder $super = null){ $this->super = $super; } function getSuper(){ return $this->super; } function getHash(){ return hashcode("\\SomethingBuilder|" . spl_object_hash($this)); } function equals($other){ return $this->getHash() === $other->getHash(); } } class Something { protected $super; protected $name; function __construct(SomethingBuilder $builder){ $this->name = $builder->getName(); $argBuilder = $builder; $immutables = []; $builders = []; do{ if(isset($immutables[$builder->getHash()])) break; // this should rather be a private class, which php doesn't have yet, but better than nothing. $immutable = $builder === $argBuilder ? $this : new class($builder->getName()) extends Something{ function __construct($name){ $this->name = $name; } }; $immutables[$builder->getHash()] = $immutable; $builders[$builder->getHash()] = $builder; }while($builder = $builder->getSuper()); foreach($immutables as $builderHash => $immutable){ $immutable->super = $immutables[$builders[$builderHash]->getSuper()->getHash()]; } } function getName(){ return $this->name; } function getSuper(){ return $this->super; } function getHash($origin = null){ if($this === $origin){ return hashcode("*RECURSION*"); }else{ return hashcode( "Something" . "{" . $this->getName() . "|" . $this->getSuper()->getHash($origin ?? $this) . "}" ); } } function equals($other){ return $this->getHash() === $other->getHash(); } } $a = new SomethingBuilder("A"); $b = new SomethingBuilder("B"); $c = new SomethingBuilder("C"); $a->setSuper($c); $b->setSuper($a); $c->setSuper($b); $immutable = new Something($a); var_dump($immutable->getHash()); var_dump($immutable->getSuper()->getHash()); var_dump($immutable->getSuper()->getSuper()->getHash()); var_dump($immutable->getSuper()->getSuper()->getSuper()->getHash()); var_dump($immutable->getSuper()->getSuper()->getSuper()->getSuper()->getHash()); assert($immutable === $immutable->getSuper()->getSuper()->getSuper()); assert( $immutable->equals( $immutable->getSuper()->getSuper()->getSuper() ) ); echo "\n\n"; $a = new SomethingBuilder("A"); $a->setSuper($a); $immutable = new Something($a); var_dump($immutable->getHash()); var_dump($immutable->getSuper()->getHash()); assert($immutable === $immutable->getSuper()); assert($immutable->equals($immutable->getSuper()));

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.0000.01818.43
8.3.50.0140.00416.46
8.3.40.0060.00918.76
8.3.30.0150.00318.84
8.3.20.0040.00420.12
8.3.10.0040.00423.61
8.3.00.0040.00422.39
8.2.180.0110.00416.38
8.2.170.0140.00022.96
8.2.160.0030.01020.56
8.2.150.0050.00324.18
8.2.140.0040.00424.66
8.2.130.0080.00026.16
8.2.120.0060.00317.75
8.2.110.0030.00720.60
8.2.100.0000.01217.84
8.2.90.0040.00419.52
8.2.80.0060.00317.97
8.2.70.0080.00017.50
8.2.60.0030.00618.05
8.2.50.0000.00818.07
8.2.40.0000.00820.96
8.2.30.0000.01118.14
8.2.20.0040.00417.83
8.2.10.0000.00718.21
8.2.00.0040.00418.09
8.1.280.0090.00925.92
8.1.270.0040.00420.45
8.1.260.0070.00326.35
8.1.250.0050.00328.09
8.1.240.0030.00622.22
8.1.230.0080.00317.60
8.1.220.0060.00317.89
8.1.210.0000.00918.77
8.1.200.0060.00317.48
8.1.190.0030.00617.48
8.1.180.0040.00418.10
8.1.170.0080.00018.76
8.1.160.0040.00422.02
8.1.150.0030.00518.98
8.1.140.0040.00417.49
8.1.130.0030.00617.80
8.1.120.0000.00817.48
8.1.110.0040.00417.51
8.1.100.0000.00717.49
8.1.90.0030.00517.47
8.1.80.0040.00417.54
8.1.70.0030.00317.45
8.1.60.0040.00417.68
8.1.50.0040.00417.59
8.1.40.0070.00317.61
8.1.30.0030.00517.65
8.1.20.0040.00417.64
8.1.10.0070.00017.57
8.1.00.0080.00017.50
8.0.300.0080.00018.77
8.0.290.0040.00416.88
8.0.280.0000.00718.59
8.0.270.0000.00717.40
8.0.260.0040.00417.42
8.0.250.0000.00817.16
8.0.240.0060.00317.05
8.0.230.0040.00417.05
8.0.220.0000.00717.09
8.0.210.0000.00717.09
8.0.200.0000.00717.21
8.0.190.0120.00017.02
8.0.180.0040.00417.12
8.0.170.0040.00417.12
8.0.160.0000.00717.04
8.0.150.0040.00417.00
8.0.140.0040.00417.02
8.0.130.0030.00313.44
8.0.120.0110.00017.07
8.0.110.0000.00717.09
8.0.100.0040.00417.05
8.0.90.0000.00717.04
8.0.80.0100.00617.07
8.0.70.0000.00716.86
8.0.60.0050.00316.91
8.0.50.0000.00816.96
8.0.30.0080.01117.02
8.0.20.0140.00517.40
8.0.10.0000.00717.13
8.0.00.0090.01016.95
7.4.330.0050.00015.08
7.4.320.0030.00316.75
7.4.300.0000.00616.69
7.4.290.0000.00716.61
7.4.280.0000.00816.56
7.4.270.0000.00716.76
7.4.260.0040.00416.70
7.4.250.0040.00416.66
7.4.240.0050.00316.63
7.4.230.0030.00316.64
7.4.220.0100.00616.64
7.4.210.0070.00716.65
7.4.200.0000.00716.72
7.4.160.0100.00716.53
7.4.150.0030.01517.40
7.4.140.0090.01117.86
7.4.130.0110.00916.59
7.4.120.0130.00716.55
7.4.110.0060.01216.43
7.4.100.0080.01416.48
7.4.90.0090.00916.69
7.4.80.0140.00319.39
7.4.70.0080.01416.85
7.4.60.0110.00616.58
7.4.50.0000.00916.79
7.4.40.0040.01216.61
7.4.30.0120.00816.52
7.4.00.0100.00815.13
7.3.330.0000.00513.32
7.3.320.0000.00513.49
7.3.310.0000.00716.52
7.3.300.0070.00016.45
7.3.290.0070.01116.54
7.3.280.0080.01116.54
7.3.270.0100.01317.40
7.3.260.0000.01816.78
7.3.250.0060.01216.56
7.3.240.0140.00716.49
7.3.230.0120.00916.69
7.3.210.0140.00416.61
7.3.200.0060.01219.39
7.3.190.0120.00816.72
7.3.180.0090.00616.43
7.3.170.0110.00716.68
7.3.160.0040.01216.61
7.3.120.0050.01014.96
7.3.110.0070.00915.09
7.3.100.0080.00815.03
7.3.90.0050.01115.00
7.3.80.0070.01014.77
7.3.70.0050.00714.96
7.3.60.0070.00915.08
7.3.50.0050.00814.97
7.3.40.0080.00714.98
7.3.30.0020.01014.95
7.3.20.0100.00716.59
7.3.10.0090.00716.64
7.3.00.0080.00616.60
7.2.330.0070.01116.89
7.2.320.0120.00816.86
7.2.310.0120.01216.89
7.2.300.0090.00916.75
7.2.290.0060.01016.82
7.2.250.0050.01615.03
7.2.240.0070.01115.11
7.2.230.0050.01015.20
7.2.220.0060.00815.25
7.2.210.0060.00815.03
7.2.200.0030.01215.16
7.2.190.0050.01215.25
7.2.180.0030.01215.04
7.2.170.0070.00915.20
7.2.160.0030.01215.25
7.2.150.0050.00516.63
7.2.140.0030.00916.76
7.2.130.0060.00916.83
7.2.120.0110.00717.02
7.2.110.0070.01016.96
7.2.100.0040.01117.02
7.2.90.0070.00717.03
7.2.80.0040.00816.70
7.2.70.0100.00716.93
7.2.60.0070.00816.90
7.2.50.0030.01016.98
7.2.40.0040.01516.84
7.2.30.0200.00717.06
7.2.20.0090.00616.68
7.2.10.0050.00816.84
7.2.00.0030.01118.11
7.1.330.0070.01015.70
7.1.320.0060.01015.66
7.1.310.0050.00715.79
7.1.300.0050.00815.68
7.1.290.0040.01115.81
7.1.280.0050.00915.78
7.1.270.0050.00715.62
7.1.260.0050.00815.59
7.1.250.0030.01015.86
7.1.200.0030.00715.63
7.1.100.0150.00718.15
7.1.70.0030.00616.87
7.1.60.0150.01120.03
7.1.50.0240.01434.93
7.1.00.0100.06722.30
7.0.200.0140.00714.97
7.0.60.0130.07720.12
7.0.50.0100.07718.07
7.0.40.0000.07720.25
7.0.30.0270.08020.23
7.0.20.0230.05020.26
7.0.10.0100.04020.25
7.0.00.0100.07720.29
5.6.280.0100.06321.17
5.6.210.0070.03720.78
5.6.200.0000.04718.18
5.6.190.0100.03720.52
5.6.180.0300.06320.77
5.6.170.0270.03020.50
5.6.160.0070.05320.71
5.6.150.0130.08318.18
5.6.140.0130.07318.28
5.6.130.0100.08018.21
5.6.120.0100.07720.95
5.6.110.0100.08321.04
5.6.100.0130.07721.00
5.6.90.0030.09021.02
5.6.80.0100.06720.39
5.5.350.0070.08020.44
5.5.340.0070.03718.09
5.5.330.0030.08720.13
5.5.320.0030.04720.30
5.5.310.0270.05320.34
5.5.300.0100.04317.98
5.5.290.0070.06018.06
5.5.280.0030.04020.76
5.5.270.0070.08320.77
5.5.260.0170.07320.77
5.5.250.0130.03720.48
5.5.240.0070.07720.27
5.4.450.0230.05319.30
5.4.440.0300.04719.61
5.4.430.0130.06019.49
5.4.420.0230.04719.33
5.4.410.0200.05019.49
5.4.400.0100.05718.84
5.4.390.0270.06019.16
5.4.380.0200.06318.99
5.4.370.0270.04719.15
5.4.360.0200.05019.30
5.4.350.0070.06319.21
5.4.340.0130.06019.38
5.4.320.0130.06019.01
5.4.310.0230.05319.15
5.4.300.0100.06019.14
5.4.290.0130.05319.05
5.4.280.0130.05719.21
5.4.270.0230.06319.30
5.4.260.0130.05318.82
5.4.250.0070.06019.15
5.4.240.0200.04719.36
5.4.230.0130.05719.02
5.4.220.0200.04719.00
5.4.210.0270.04319.12
5.4.200.0200.05316.90
5.4.190.0230.05719.16
5.4.180.0070.06019.32
5.4.170.0270.04319.01
5.4.160.0170.05018.91
5.4.150.0170.05719.05
5.4.140.0100.05016.43
5.4.130.0030.05316.42
5.4.120.0300.05016.59
5.4.110.0670.05716.36
5.4.100.0770.04016.38
5.4.90.0670.05016.38
5.4.80.0800.06716.57
5.4.70.0600.05316.39
5.4.60.0030.03316.34
5.4.50.0070.03016.26
5.4.40.0230.04316.38
5.4.30.0230.05316.34
5.4.20.0200.04016.23

preferences:
55.09 ms | 400 KiB | 5 Q