3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { function Foo($name) { // create a reference inside the global array $globalref global $globalref;//<--- variável global WTF que tenta exemplicar a diferença //do new e do &= $globalref[] = &$this; // set name to passed value $this->setName($name); // and put it out $this->echoName(); } function echoName() { echo "<br />", $this->name; } function setName($name) { $this->name = $name; } } $bar1 = new Foo('set in constructor'); $bar1->echoName(); $globalref[0]->echoName(); $bar2 =& new Foo('set in constructor'); $bar2->echoName(); $globalref[1]->echoName(); // now we will change the name. what do you expect? // you could expect that both $bar1 and $globalref[0] change their names... $bar1->setName('set from outside'); // as mentioned before this is not the case. $bar1->echoName(); $globalref[0]->echoName(); /* output: set from outside set in constructor */ // let us see what is different with $bar2 and $globalref[1] $bar2->setName('set from outside'); // luckily they are not only equal, they are the same variable // thus $bar2->name and $globalref[1]->name are the same too $bar2->echoName(); $globalref[1]->echoName(); $bar1->setName('set from outside'); // as mentioned before this is not the case. $bar1->echoName(); $globalref[0]->echoName(); /* output: set from outside set in constructor */ // let us see what is different with $bar2 and $globalref[1] $bar2->setName('set from outside'); // luckily they are not only equal, they are the same variable // thus $bar2->name and $globalref[1]->name are the same too $bar2->echoName(); $globalref[1]->echoName(); ?>

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)
5.6.280.0030.05020.82
5.6.210.0070.08320.67
5.6.200.0070.07718.22
5.6.190.0070.04020.39
5.6.180.0270.04720.52
5.6.170.0230.08020.56
5.6.160.0070.08320.55
5.6.150.0030.06018.16
5.6.140.0030.04018.18
5.6.130.0070.08718.18
5.6.120.0100.03721.02
5.6.110.0100.06320.99
5.6.100.0030.07320.98
5.6.90.0100.08321.00
5.6.80.0000.09020.41
5.5.350.0030.08720.54
5.5.340.0070.03317.94
5.5.330.0070.06320.27
5.5.320.0030.08020.36
5.5.310.0400.07320.27
5.5.300.0030.08717.95
5.5.290.0100.05317.95
5.5.280.0130.04320.63
5.5.270.0030.04720.86
5.5.260.0070.04020.80
5.5.250.0070.07720.62
5.5.240.0070.07720.16
5.4.450.0700.05719.16
5.4.440.0630.07019.69
5.4.430.0630.05019.42
5.4.420.0600.05719.30
5.4.410.0770.04719.47
5.4.400.0670.05319.29
5.4.390.0600.05719.23
5.4.380.0670.05019.28
5.4.370.0700.05319.10
5.4.360.0670.05719.26
5.4.350.0670.05719.26
5.4.340.0770.05019.28
5.4.320.0870.05719.14
5.4.310.0730.04719.00
5.4.300.0700.06719.01
5.4.290.0800.04719.36
5.4.280.0700.05719.22
5.4.270.0830.06019.27
5.4.260.0770.05319.27
5.4.250.0630.06019.28
5.4.240.0800.05319.28
5.4.230.0630.05719.01
5.4.220.0670.06018.86
5.4.210.0730.05019.16
5.4.200.0700.05316.90
5.4.190.0770.05318.98
5.4.180.0770.06719.02
5.4.170.0730.06019.09
5.4.160.0770.05019.05
5.4.150.0800.05018.89
5.4.140.0670.05316.57
5.4.130.0800.04316.32
5.4.120.0630.04316.34
5.4.110.0530.05016.48
5.4.100.0030.05716.55
5.4.90.0000.06016.53
5.4.80.0500.04316.49
5.4.70.0770.04316.36
5.4.60.0730.04716.47
5.4.50.0670.04316.48
5.4.40.0930.04716.55
5.4.30.0670.05716.63
5.4.20.0800.04316.40
5.4.10.0770.04016.69
5.4.00.0730.04715.89
5.3.290.0670.05714.70
5.3.280.0700.05014.51
5.3.270.0700.05314.68
5.3.260.0630.06014.86
5.3.250.0670.05314.66
5.3.240.0730.05314.63
5.3.230.0830.04314.65
5.3.220.0630.05714.59
5.3.210.0600.05014.47
5.3.200.0600.05714.56
5.3.190.0570.05314.48
5.3.180.0630.04314.58
5.3.170.0630.04714.63
5.3.160.0700.04014.48
5.3.150.0530.05314.48
5.3.140.0700.04014.45
5.3.130.0600.05314.47
5.3.120.0730.05714.45
5.3.110.0770.04714.52
5.3.100.0870.03713.94
5.3.90.0730.05314.01
5.3.80.0770.04713.86
5.3.70.0700.06013.94
5.3.60.0800.05714.02
5.3.50.0730.05013.96
5.3.40.0700.05014.01
5.3.30.0700.05013.78
5.3.20.0770.05713.76
5.3.10.0730.04313.59
5.3.00.0730.04313.54
5.2.170.0670.04011.17
5.2.160.0600.03711.06
5.2.150.0530.04311.21
5.2.140.0600.04311.16
5.2.130.0530.04011.17
5.2.120.0600.04011.09
5.2.110.0700.04011.03
5.2.100.0500.04311.07
5.2.90.0600.04011.34
5.2.80.0600.04011.06
5.2.70.0330.04711.33
5.2.60.0400.04011.11
5.2.50.0070.04011.25
5.2.40.0000.04711.15
5.2.30.0070.04011.08
5.2.20.0430.03711.19
5.2.10.0470.03711.09
5.2.00.0530.03310.74
5.1.60.0570.02710.07
5.1.50.0470.03310.01
5.1.40.0470.03010.05
5.1.30.0570.03010.27
5.1.20.0300.05010.59
5.1.10.0330.04010.01
5.1.00.0370.0379.97
5.0.50.0200.0308.63
5.0.40.0070.0278.47
5.0.30.0130.0378.29
5.0.20.0030.0278.05
5.0.10.0030.0278.21
5.0.00.0030.0438.07
4.4.90.0000.0275.87
4.4.80.0000.0235.88
4.4.70.0000.0235.81
4.4.60.0200.0235.78
4.4.50.0200.0235.86
4.4.40.0270.0335.86
4.4.30.0200.0235.89
4.4.20.0200.0235.84
4.4.10.0230.0205.92
4.4.00.0270.0305.89
4.3.110.0270.0175.78
4.3.100.0230.0205.79
4.3.90.0270.0175.78
4.3.80.0200.0375.77
4.3.70.0230.0205.68
4.3.60.0300.0175.72
4.3.50.0130.0205.70
4.3.40.0170.0375.68
4.3.30.0070.0304.58
4.3.20.0070.0274.55
4.3.10.0100.0274.49
4.3.00.0070.0237.10

preferences:
133.5 ms | 1394 KiB | 7 Q