3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Reference { private static $DATA = []; private $index = 0; public function __construct($value) { // cannot create a reference of a reference if ($value instanceof self) { $this->index = $value->index; } else { $this->index = count(self::$DATA); self::$DATA[$this->index] = $value; } } public function get() { return self::$DATA[$this->index]; } public function set($value) { self::$DATA[$this->index] = $value; } } $x = [1, 2, 3]; // foreach($x as &$ref) { ... } /* $x[0] */ $x[0] = new Reference($x[0]); // Reference#0(index 0) = 1 $ref = clone $x[0]; // Reference#1(index 0) $ref->set($ref->get() + 100); // set index 0 = 101 /* $x[1] */ $x[1] = new Reference($x[1]); // Reference#2(index 1) = 2 $ref = clone $x[1]; // Reference#3(index 1) $x[0] = $x[0]->get(); // without $ref, $x[0] is the only reference to its value and demoted back to a value $ref->set($ref->get() + 100); // set index 1 = 101 /* $x[2] */ $x[2] = new Reference($x[2]); // Reference#4(index 2) = 3 $ref = clone $x[2]; // Reference#5(index 2) $x[1] = $x[1]->get(); // demoted $ref->set($ref->get() + 100); // set index 2 = 103 // end foreach /* $x is [101, 102, Reference#4(index 2)] */ /* $ref remains as Reference#5(index 2) */ $b = $x; // $b[0] = clone $x[0]; - except $x[0] is an integer so this was automatic // $b[1] = clone $x[1]; - same $b[2] = clone $x[2]; // creating a copy of what was in $x[2] /* $b is [101, 102, Reference#6(index 2)] - a different Reference as $x[2] and $ref but the same underlying value */ $b[0] = 0; // foreach($x as &$ref) { ... } /* $x[0] */ $x[0] = new Reference($x[0]); // Reference#7(index 3) = 101 $ref = clone $x[0]; // Reference#8(index 3) $ref->set($ref->get() + 100); // set index 3 = 201 /* $x[1] */ $x[1] = new Reference($x[1]); // Reference#9(index 4) = 102 $ref = clone $x[1]; // Reference#10(index 4) $x[0] = $x[0]->get(); // demoted $ref->set($ref->get() + 100); // set index 4 = 202 /* $x[2] */ // $x[2] = new Reference($x[2]); // - except $x[2] is already Reference#4(index 2) $ref = clone $x[2]; // Reference#11(index 2) $x[1] = $x[1]->get(); // demoted $ref->set($ref->get() + 100); // set index 2 = 203 // end foreach /* $x is [201, 202, Reference#4(index 2)] */ /* $ref remains as Reference#11(index 2) */ /* $b was not modified during the foreach and still contains [0, 102, Reference#6(index 2)] */ /* however the underlying value of the Reference did change */ // var_dump($b); var_dump([$b[0], $b[1], $b[2]->get()]);

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.70.0060.00916.63
8.3.60.0090.01216.88
8.3.50.0080.01221.93
8.3.40.0140.00718.97
8.3.30.0140.00018.84
8.3.20.0080.00019.46
8.3.10.0040.00421.89
8.3.00.0040.00419.08
8.2.180.0100.00618.16
8.2.170.0070.00722.96
8.2.160.0120.00321.99
8.2.150.0000.00824.18
8.2.140.0050.00224.66
8.2.130.0030.00718.04
8.2.120.0080.00026.35
8.2.110.0150.00621.18
8.2.100.0120.00018.03
8.2.90.0000.00819.14
8.2.80.0000.00817.97
8.2.70.0040.00417.50
8.2.60.0080.00018.05
8.2.50.0040.00418.09
8.2.40.0000.00822.31
8.2.30.0040.00419.62
8.2.20.0040.00417.79
8.2.10.0030.00518.23
8.2.00.0060.00618.16
8.1.280.0130.00725.92
8.1.270.0080.00023.84
8.1.260.0090.00028.09
8.1.250.0040.00428.09
8.1.240.0030.00722.54
8.1.230.0070.00319.10
8.1.220.0050.00517.78
8.1.210.0000.00818.77
8.1.200.0060.00317.25
8.1.190.0080.00017.23
8.1.180.0040.00418.10
8.1.170.0000.00818.71
8.1.160.0000.00720.81
8.1.150.0040.00419.07
8.1.140.0040.00419.59
8.1.130.0080.00017.69
8.1.120.0000.00717.56
8.1.110.0000.00717.39
8.1.100.0040.00417.40
8.1.90.0000.00817.54
8.1.80.0000.00817.52
8.1.70.0040.00417.36
8.1.60.0030.00517.65
8.1.50.0030.00617.50
8.1.40.0080.00017.55
8.1.30.0040.00417.73
8.1.20.0080.00017.70
8.1.10.0060.00317.65
8.1.00.0080.00017.45
8.0.300.0000.00718.77
8.0.290.0000.00716.63
8.0.280.0000.00718.41
8.0.270.0030.00317.38
8.0.260.0030.00317.23
8.0.250.0030.00316.95
8.0.240.0040.00416.95
8.0.230.0070.00016.98
8.0.220.0040.00416.86
8.0.210.0030.00316.81
8.0.200.0050.00217.02
8.0.190.0030.00517.00
8.0.180.0070.00016.97
8.0.170.0080.00017.02
8.0.160.0080.00017.04
8.0.150.0000.00816.89
8.0.140.0040.00416.76
8.0.130.0000.00513.41
8.0.120.0040.00416.92
8.0.110.0040.00416.86
8.0.100.0000.00816.93
8.0.90.0040.00416.89
8.0.80.0130.00916.99
8.0.70.0070.00016.98
8.0.60.0080.00016.82
8.0.50.0000.00716.81
8.0.30.0090.00817.07
8.0.20.0180.00317.43
8.0.10.0050.00317.02
8.0.00.0120.00716.76
7.4.330.0050.00015.11
7.4.320.0040.00416.55
7.4.300.0100.00016.66
7.4.290.0030.00316.65
7.4.280.0090.00316.46
7.4.270.0070.00016.55
7.4.260.0000.00716.68
7.4.250.0000.00716.52
7.4.240.0070.00016.51
7.4.230.0080.00016.76
7.4.220.0060.01116.72
7.4.210.0080.01116.59
7.4.200.0070.00016.65
7.4.160.0090.00616.74
7.4.150.0210.01017.40
7.4.140.0110.00617.86
7.4.130.0080.01016.47
7.4.120.0140.00616.66
7.4.110.0070.01016.50
7.4.100.0140.01016.57
7.4.90.0070.01016.55
7.4.80.0150.00619.39
7.4.70.0070.01016.35
7.4.60.0060.01016.63
7.4.50.0030.01016.43
7.4.40.0060.01216.36
7.4.30.0110.00516.60
7.4.00.0070.01015.07
7.3.330.0050.00013.39
7.3.320.0000.00513.27
7.3.310.0040.00416.50
7.3.300.0000.00716.27
7.3.290.0000.00716.40
7.3.280.0100.00716.42
7.3.270.0170.00417.40
7.3.260.0090.00916.62
7.3.250.0100.01116.54
7.3.240.0130.00616.59
7.3.230.0190.00316.39
7.3.210.0130.00316.61
7.3.200.0100.00719.39
7.3.190.0140.00316.38
7.3.180.0110.01116.50
7.3.170.0060.01216.54
7.3.160.0040.01216.70
7.3.120.0000.01515.15
7.3.110.0090.00614.80
7.3.100.0000.01414.81
7.3.90.0000.01614.88
7.3.80.0060.00914.54
7.3.70.0000.01214.78
7.3.60.0130.00014.63
7.3.50.0140.00014.80
7.3.40.0070.00714.68
7.3.30.0140.00014.97
7.3.20.0040.01116.72
7.3.10.0090.00416.59
7.3.00.0080.00816.68
7.2.330.0030.01916.71
7.2.320.0080.00816.68
7.2.310.0040.01416.77
7.2.300.0140.00316.76
7.2.290.0060.01616.51
7.2.240.0080.00315.24
7.2.230.0110.00414.87
7.2.220.0070.00715.25
7.2.210.0060.00614.98
7.2.200.0070.00715.32
7.2.190.0080.00415.03
7.2.180.0060.00315.26
7.2.170.0060.00915.20
7.2.160.0050.00515.16
7.2.150.0070.01017.12
7.2.140.0070.00716.78
7.2.130.0020.01517.04
7.2.120.0100.00516.86
7.2.110.0070.01116.84
7.2.100.0100.00616.91
7.2.90.0080.00816.97
7.2.80.0090.00616.90
7.2.70.0080.00716.76
7.2.60.0070.00717.06
7.2.50.0090.00416.64
7.2.40.0030.01016.89
7.2.30.0080.00516.97
7.2.20.0020.01216.81
7.2.10.0070.00616.79
7.2.00.0030.00717.75
7.1.330.0060.00615.60
7.1.320.0040.01215.77
7.1.310.0120.00315.89
7.1.300.0030.01215.74
7.1.290.0000.01415.88
7.1.280.0000.00815.75
7.1.270.0000.01215.98
7.1.260.0070.01015.88
7.1.250.0090.00715.82
7.1.200.0090.00315.86
7.1.100.0160.00317.99
7.1.70.0000.00817.38
7.1.60.0060.01919.85
7.1.00.0070.07322.42
7.0.200.0120.00314.98
7.0.60.0100.05720.12
7.0.50.0200.05320.25
7.0.40.0270.04720.26
7.0.30.0130.05720.26
7.0.20.0230.05320.35
7.0.10.0130.06320.47
7.0.00.0200.06020.45
5.6.280.0000.07721.15
5.6.210.0100.06020.73
5.6.200.0100.06321.05
5.6.190.0200.06321.10
5.6.180.0230.04721.18
5.6.170.0200.05021.08
5.6.160.0200.05721.05
5.6.150.0230.06021.14
5.6.140.0170.05321.19
5.6.130.0470.06021.08
5.6.120.0170.06321.14
5.6.110.0230.05721.09
5.6.100.0200.05021.07
5.6.90.0070.06720.96
5.6.80.0230.04720.52
5.6.70.0100.06020.43
5.6.60.0200.04720.40
5.6.50.0130.06720.61
5.6.40.0070.05720.50
5.6.30.0300.05720.58
5.6.20.0370.05320.49
5.6.10.0330.05720.43
5.6.00.0400.05020.53
5.5.350.0300.04320.60
5.5.340.0170.05720.76
5.5.330.0170.05720.89
5.5.320.0200.04720.79
5.5.310.0170.06720.77
5.5.300.0070.06720.89
5.5.290.0170.05720.90
5.5.280.0200.05320.91
5.5.270.0170.05321.04
5.5.260.0230.04320.87
5.5.250.0270.06320.86
5.5.240.0170.05320.28
5.5.230.0200.05720.27
5.5.220.0200.05020.42
5.5.210.0170.05320.42
5.5.200.0070.05720.32
5.5.190.0530.05020.24
5.5.180.0470.04720.16
5.5.160.0330.06720.22
5.5.150.0470.05320.23
5.5.140.0400.06020.23
5.5.130.0430.05720.20
5.5.120.0400.06020.22
5.5.110.0430.05320.41
5.5.100.0370.05720.14
5.5.90.0430.05020.10
5.5.80.0400.05720.07
5.5.70.0370.05720.28
5.5.60.0530.03720.20
5.5.50.0370.05320.14
5.5.40.0430.04720.07
5.5.30.0300.06020.15
5.5.20.0430.05720.08
5.5.10.0370.06020.09
5.5.00.0430.05320.05

preferences:
61.22 ms | 401 KiB | 5 Q