3v4l.org

run code in 300+ PHP versions simultaneously
<?php var_dump(php_uname('s')); $base_dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR; file_put_contents($base_dir . 'Baz.php', "<?php namespace Foo\Bar; class BAZ {}"); file_put_contents($base_dir . 'Buz.php', "<?php namespace Foo\Bar; class Buz {}"); spl_autoload_register(function ($class) { echo "Trying to autoload $class\n"; // project-specific namespace prefix $prefix = 'Foo\\Bar\\'; // base directory for the namespace prefix global $base_dir; # = __DIR__ . '/src/'; // does the class use the namespace prefix? $len = strlen($prefix); if (strncmp($prefix, $class, $len) !== 0) { // no, move to the next registered autoloader return; } // get the relative class name $relative_class = substr($class, $len); // replace the namespace prefix with the base directory, replace namespace // separators with directory separators in the relative class name, append // with .php $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php'; // if the file exists, require it if (file_exists($file)) { require $file; } else { echo "Could not require $file\n"; } }); // This works as expected because the class name matches the intended // case in the file and as it is represented on disk. $c1 = new \Foo\Bar\Baz(); // This works because PHP is PHP. This is not even going to hit the // PSR-4 autoloader. The *usage* of this classname by the user is not // PSR-4 compliant but that does not make the *autoloader* noncompliant. $c2 = new \Foo\Bar\BAZ(); var_dump($c1 == $c2); // This is going to be rejected by the PSR-4 autoloader implementation. // That is fine *and expected* because the *usage* of the classname by // the user is incorrect. // // On some platforms this may actually work but that is a byproduct of // certain platforms not caring about case. But again, the *usage* of // this classname *in this context* is not PSR-4 compliant. // // PSR-4 says that case is important and that case MUST be taken into // account when creating the file path representing the class name. It // also dictates that case MUST be taken into account when you create // files on disk for the FQCN in question. // // If the FQCN is \Foo\Bar\Baz in src/Baz.php, then specifying the class // with any other case than \Foo\Bar\Baz by the user is not compliant // with PSR-4. This is a problem with the user using the wrong classname // and the user should not expect this to work if they are following // the documented case for the classes in question. // // In some cases the planets will align and allow this to work anyway. // For instance, on Windows this actually "works." But just because it // "works" on Windows that does not mean it is correct. // // All the autoloader implementation can do is *try* to ensure it is // using the right case. If PHP / the platform discards that information // it is out of scope of PSR-4. The important thing is that if the author // of the class says that the class name is \Foo\Bar\Buz, the user of the // class needs to use it as \Foo\Bar\Buz. The user MAY use it with a // different case like \Foo\Bar\BUZ, in an some cases that MAY "work", but // whether the autoloader loads the class or not, the user's *usage* is // not compliant with PSR-4. $c3 = new \Foo\Bar\BUZ(); $c4 = new \Foo\Bar\Buz(); var_dump($c3 == $c4); // In the end, the fact that PHP considers \Foo\Bar\Buz and \Foo\Bar\BUZ // to be the same complicates things. This detail was ignored by PSR-0 // and it was one of the big things that people considered "bad" about it. // // The intent with PSR-4 is to ensure that people do not rely on the fact // that PHP is fuzzy in its handling of case for classnames and namespaces // and ensure that everyone uses the same case in all contexts for the // same class. // // There ARE edge cases where PHP will allow things that it shoudln't, but // PSR-4 autoloader implementations only need care about ensuring that it // locates and loads files using the case for the classname given it. As // long as this is the case, anything else PHP does weird is out of scope // for PSR-4 autoloader implementations. // // Authors need to ensure that if they write a package with a classname of // \Foo\Bar\Buz that they honor the case on the filesystem as well. If they // do not ( say [\Foo\Bar, src/] with "Foo\Bar\Baz" defined in src/BAZ.php ) // then their package is not PSR-4 compliant even if a PSR-4 autoloader may // sometimes load \Foo\Bar\Baz from src/BAZ.php on some platforms. // // Users of a class need to ensure that they use the correct case for any // class they load that is autoloaded by PSR-4. This means that if they use // a package that defines [\Foo\Bar, src/] with "Foo\Bar\Baz" in src/Baz.php, // they MUST call `new \Foo\Bar\Baz()` or their *usage* of the class is not // PSR-4 compliant, even if on some platforms they might get to load the // "correct class" with `new \foo\bar\baz()`. // I don't know if this will change any minds, but hopefully it helps reveal // the intent behind the case rules in PSR-4. The intention was to ensure // everyone is consistent in the case for FQCN specifically because PHP is // loose in how it handles case in some cases. // // An autoloader is not required to ensure that the case for the file it // includes matches the requested classname. It is only required to make a // reasonable effort to ensure that it uses the requested classname in // building the path to the file on disk that may contain the class in // question. // // An autoloader is only part of the PSR-4 equation. There are also class // authors and class users as well. The case rules apply to all to ensure // they are all speaking the same case.

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.0170.00316.75
8.3.50.0200.00516.48
8.3.40.0060.00919.09
8.3.30.0080.00818.96
8.3.20.0090.00018.96
8.3.10.0040.00419.03
8.3.00.0050.00319.38
8.2.180.0110.00716.63
8.2.170.0070.01422.96
8.2.160.0130.00920.40
8.2.150.0050.00324.18
8.2.140.0050.00324.66
8.2.130.0040.00426.16
8.2.120.0040.00419.22
8.2.110.0080.00320.97
8.2.100.0060.00617.71
8.2.90.0060.00319.30
8.2.80.0070.00019.23
8.2.70.0050.00517.63
8.2.60.0000.01017.93
8.2.50.0040.00418.07
8.2.40.0040.00418.07
8.2.30.0080.00018.21
8.2.20.0060.00317.84
8.2.10.0040.00417.78
8.2.00.0040.00417.97
8.1.280.0150.00025.92
8.1.270.0040.00424.66
8.1.260.0080.00026.35
8.1.250.0040.00428.09
8.1.240.0090.00022.47
8.1.230.0030.01021.13
8.1.220.0000.00817.74
8.1.210.0030.00618.97
8.1.200.0000.00917.25
8.1.190.0040.00417.66
8.1.180.0100.00018.10
8.1.170.0000.00920.68
8.1.160.0060.00318.89
8.1.150.0040.00418.75
8.1.140.0080.00017.56
8.1.130.0030.00317.80
8.1.120.0050.00217.45
8.1.110.0030.00517.54
8.1.100.0050.00317.45
8.1.90.0050.00317.52
8.1.80.0030.00517.55
8.1.70.0030.00317.42
8.1.60.0030.00617.59
8.1.50.0040.00417.49
8.1.40.0030.00517.47
8.1.30.0060.00317.68
8.1.20.0030.00517.77
8.1.10.0040.00417.56
8.1.00.0030.00617.62
8.0.300.0050.00220.05
8.0.290.0000.00816.88
8.0.280.0040.00418.48
8.0.270.0030.00517.36
8.0.260.0050.00316.99
8.0.250.0050.00317.00
8.0.240.0040.00417.10
8.0.230.0040.00417.03
8.0.220.0000.00716.93
8.0.210.0040.00416.93
8.0.200.0000.00616.99
8.0.190.0000.00817.14
8.0.180.0110.00016.98
8.0.170.0060.00316.98
8.0.160.0030.00516.96
8.0.150.0030.00517.07
8.0.140.0030.00717.03
8.0.130.0000.00613.55
8.0.120.0040.00416.95
8.0.110.0040.00417.07
8.0.100.0040.00416.95
8.0.90.0070.00016.86
8.0.80.0030.01417.13
8.0.70.0030.00516.93
8.0.60.0000.00817.12
8.0.50.0060.00316.95
8.0.30.0110.00817.06
8.0.20.0100.00817.11
8.0.10.0040.00417.16
8.0.00.0100.01116.97
7.4.330.0030.00312.95
7.4.320.0000.00716.65
7.4.300.0040.00416.62
7.4.290.0030.00516.50
7.4.280.0040.00416.45
7.4.270.0000.00616.55
7.4.260.0030.00313.32
7.4.250.0040.00416.45
7.4.240.0060.00216.58
7.4.230.0000.00716.74
7.4.220.0120.01216.63
7.4.210.0070.00716.57
7.4.200.0040.00416.55
7.4.190.0040.00416.43
7.4.160.0100.00716.45
7.4.150.0060.01316.68
7.4.140.0110.01116.53
7.4.130.0120.00716.59
7.4.120.0090.00916.47
7.4.110.0160.00516.77
7.4.100.0170.00016.51
7.4.90.0070.01316.55
7.4.80.0030.01319.39
7.4.70.0060.01216.49
7.4.60.0030.01416.57
7.4.50.0030.00616.58
7.4.40.0070.00716.54
7.4.30.0070.01116.57
7.4.10.0090.01014.80
7.4.00.0100.00815.14
7.3.330.0030.00313.60
7.3.320.0000.00613.50
7.3.310.0070.00016.54
7.3.300.0030.00316.50
7.3.290.0060.01516.59
7.3.280.0050.01216.54
7.3.270.0100.00716.64
7.3.260.0140.00316.54
7.3.250.0110.00716.50
7.3.240.0060.01016.50
7.3.230.0170.00016.68
7.3.210.0110.00716.52
7.3.200.0100.00716.56
7.3.190.0110.00616.49
7.3.180.0100.00616.52
7.3.170.0120.00916.40
7.3.160.0120.00416.57
7.3.130.0070.01115.04
7.3.120.0100.00714.94
7.3.110.0090.00814.89
7.3.100.0070.00514.88
7.3.90.0030.01114.84
7.3.80.0060.00615.06
7.3.70.0060.00514.88
7.3.60.0050.00914.86
7.3.50.0080.00214.86
7.3.40.0090.00314.92
7.3.30.0100.00614.93
7.3.20.0090.00516.71
7.3.10.0060.00616.68
7.3.00.0060.00516.66
7.2.330.0000.01816.83
7.2.320.0040.01316.63
7.2.310.0060.01316.70
7.2.300.0200.00316.78
7.2.290.0090.01516.62
7.2.260.0000.01914.98
7.2.250.0080.00715.00
7.2.240.0090.00915.14
7.2.230.0030.00915.21
7.2.220.0070.00715.03
7.2.210.0070.00515.24
7.2.200.0060.00915.13
7.2.190.0070.00315.05
7.2.180.0040.01115.20
7.2.170.0050.00815.06
7.2.160.0110.00415.00
7.2.150.0060.00916.88
7.2.140.0080.00816.95
7.2.130.0030.00917.10
7.2.120.0120.00317.07
7.2.110.0070.01016.91
7.2.100.0070.00416.99
7.2.90.0060.01017.05
7.2.80.0040.01417.13
7.2.70.0090.00616.98
7.2.60.0060.00916.99
7.2.50.0030.01517.04
7.2.40.0040.01117.00
7.2.30.0090.00617.02
7.2.20.0030.01217.08
7.2.10.0000.01117.05
7.2.00.0220.01018.08
7.1.330.0030.01115.77
7.1.320.0040.01116.07
7.1.310.0060.00715.94
7.1.300.0040.01015.74
7.1.290.0060.00515.79
7.1.280.0070.00615.79
7.1.270.0090.00515.83
7.1.260.0020.01015.94
7.1.250.0080.00415.79
7.1.240.0090.00615.48
7.1.230.0000.01415.98
7.1.220.0040.01115.81
7.1.210.0000.01515.77
7.1.200.0060.00615.84
7.1.190.0090.00315.94
7.1.180.0030.01015.88
7.1.170.0030.00715.48
7.1.160.0070.00715.98
7.1.150.0080.00015.77
7.1.140.0030.00715.92
7.1.130.0040.00415.83
7.1.120.0140.00015.96
7.1.110.0070.00715.90
7.1.100.0000.01017.01
7.1.90.0080.00615.93
7.1.80.0060.00615.86
7.1.70.0020.00816.48
7.1.60.0100.00917.59
7.1.50.0080.01016.36
7.1.40.0090.00615.78
7.1.30.0060.00615.77
7.1.20.0040.01215.64
7.1.10.0040.00815.96
7.1.00.0030.02219.21
7.0.330.0130.00315.41
7.0.320.0000.01215.51
7.0.310.0090.00615.46
7.0.300.0040.00415.52
7.0.290.0110.00315.28
7.0.280.0070.00415.19
7.0.270.0070.00315.27
7.0.260.0110.00415.46
7.0.250.0000.01515.43
7.0.240.0060.00615.52
7.0.230.0030.00615.40
7.0.220.0030.01015.48
7.0.210.0000.01315.36
7.0.200.0070.00315.99
7.0.190.0070.00315.57
7.0.180.0120.00015.41
7.0.170.0000.01315.66
7.0.160.0070.00615.72
7.0.150.0040.00815.38
7.0.140.0050.03718.90
7.0.130.0030.00715.23
7.0.120.0060.03518.65
7.0.110.0030.01015.36
7.0.100.0030.01015.32
7.0.90.0070.00415.41
7.0.80.0110.00315.69
7.0.70.0070.00415.50
7.0.60.0060.04317.67
7.0.50.0070.04216.67
7.0.40.0050.02415.66
7.0.30.0100.04115.75
7.0.20.0050.02815.50
7.0.10.0070.04015.63
7.0.00.0060.02615.62
5.6.400.0060.00314.61
5.6.390.0040.00814.44
5.6.380.0130.00314.21
5.6.370.0030.01014.15
5.6.360.0050.00814.20
5.6.350.0040.00414.41
5.6.340.0040.00814.19
5.6.330.0110.00414.05
5.6.320.0070.00714.21
5.6.310.0090.00614.38
5.6.300.0040.01114.56
5.6.290.0090.00614.41
5.6.280.0030.04317.54
5.6.270.0060.00914.48
5.6.260.0030.00914.45
5.6.250.0000.01014.34
5.6.240.0030.00914.21
5.6.230.0060.00814.36
5.6.220.0030.00914.33
5.6.210.0070.04217.54
5.6.200.0030.03816.18
5.6.190.0030.04516.22
5.6.180.0100.04216.26
5.6.170.0090.04316.26
5.6.160.0030.04916.38
5.6.150.0080.03516.13
5.6.140.0030.02516.46
5.6.130.0060.04316.46
5.6.120.0070.04416.32
5.6.110.0050.02716.28
5.6.100.0080.03316.29
5.6.90.0030.04516.13
5.6.80.0020.05115.94
5.6.70.0070.02516.10
5.6.60.0050.02215.97
5.6.50.0120.03715.97
5.6.40.0070.02715.82
5.6.30.0050.03216.08
5.6.20.0010.03815.86
5.6.10.0060.04216.08
5.6.00.0000.04715.95
5.5.380.0000.01514.46
5.5.370.0070.00714.01
5.5.360.0080.00414.24
5.5.350.0150.04817.47
5.5.340.0080.02516.11
5.5.330.0060.04116.22
5.5.320.0110.04216.10
5.5.310.0080.04316.27
5.5.300.0030.04116.31
5.5.290.0070.02616.02
5.5.280.0040.05015.99
5.5.270.0010.03216.06
5.5.260.0070.04316.12
5.5.250.0080.02515.90
5.5.240.0070.02715.82
5.5.230.0070.02715.87
5.5.220.0040.03715.68
5.5.210.0030.04915.87
5.5.200.0050.04015.77
5.5.190.0080.03715.81
5.5.180.0030.04615.84
5.5.170.0000.01414.44
5.5.160.0030.03715.82
5.5.150.0000.04815.80
5.5.140.0080.04015.63
5.5.130.0040.04515.84
5.5.120.0030.03115.71
5.5.110.0020.04915.86
5.5.100.0120.03215.60
5.5.90.0020.04815.68
5.5.80.0070.04015.61
5.5.70.0100.03415.71
5.5.60.0080.03715.69
5.5.50.0120.04015.82
5.5.40.0120.03915.74
5.5.30.0110.03815.83
5.5.20.0060.02915.74
5.5.10.0090.02715.77
5.5.00.0070.04715.82
5.4.450.0020.02715.28
5.4.440.0070.03115.17
5.4.430.0100.03715.09
5.4.420.0090.04015.22
5.4.410.0050.02815.12
5.4.400.0040.04014.88
5.4.390.0050.02314.87
5.4.380.0020.02615.00
5.4.370.0090.02515.07
5.4.360.0040.03315.10
5.4.350.0000.02915.09
5.4.340.0070.03715.13
5.4.330.0100.00011.01
5.4.320.0070.03015.11
5.4.310.0060.03115.07
5.4.300.0070.04015.20
5.4.290.0080.02315.03
5.4.280.0100.03714.98
5.4.270.0050.04114.74
5.4.260.0120.03714.94
5.4.250.0070.02514.96
5.4.240.0040.03115.01
5.4.230.0030.03015.08
5.4.220.0070.03614.99
5.4.210.0030.04014.83
5.4.200.0020.02815.08
5.4.190.0030.03614.91
5.4.180.0020.03815.02
5.4.170.0030.03415.04
5.4.160.0050.04015.00
5.4.150.0070.02515.05
5.4.140.0120.03513.71
5.4.130.0070.03413.70
5.4.120.0040.03113.66
5.4.110.0030.02813.64
5.4.100.0070.02913.72
5.4.90.0050.02213.75
5.4.80.0050.03713.72
5.4.70.0080.03713.57
5.4.60.0060.03213.77
5.4.50.0020.04013.76
5.4.40.0060.02813.77
5.4.30.0050.02813.63
5.4.20.0000.04713.63
5.4.10.0030.03913.74
5.4.00.0070.02013.44
5.3.290.0080.04012.67
5.3.280.0030.02112.56
5.3.270.0120.03212.66
5.3.260.0020.03112.68
5.3.250.0050.03812.56
5.3.240.0040.03512.63
5.3.230.0050.03312.54
5.3.220.0070.03712.59
5.3.210.0000.04712.49
5.3.200.0020.04312.44
5.3.190.0070.03812.58
5.3.180.0020.02912.74
5.3.170.0050.03312.54
5.3.160.0110.03512.50
5.3.150.0070.03812.52
5.3.140.0070.03612.63
5.3.130.0030.04512.63
5.3.120.0090.03512.72
5.3.110.0060.04012.59
5.3.100.0030.04212.31
5.3.90.0060.03312.42
5.3.80.0030.02512.39
5.3.70.0030.02312.27
5.3.60.0060.03812.34
5.3.50.0040.04212.19
5.3.40.0090.02512.28
5.3.30.0060.02312.23
5.3.20.0050.02712.22
5.3.10.0060.03312.11
5.3.00.0020.04012.00
5.2.170.0100.06011.18
5.2.160.0070.05311.12
5.2.150.0000.03310.97
5.2.140.0070.05711.12
5.2.130.0100.05310.93
5.2.120.0130.05711.08
5.2.110.0000.06311.05
5.2.100.0070.04011.06
5.2.90.0070.05311.03
5.2.80.0100.05711.07
5.2.70.0100.05711.09
5.2.60.0070.04711.04
5.2.50.0070.06010.85
5.2.40.0100.04310.95
5.2.30.0070.06011.12
5.2.20.0070.04010.90
5.2.10.0030.03310.71
5.2.00.0030.06010.75
5.1.60.0000.0379.94
5.1.50.0000.0279.99
5.1.40.0100.05010.02
5.1.30.0030.06010.37
5.1.20.0030.02710.36
5.1.10.0030.05710.05
5.1.00.0070.05710.11
5.0.50.0070.0438.59
5.0.40.0000.0408.48
5.0.30.0030.0638.17
5.0.20.0070.0308.18
5.0.10.0070.0378.11
5.0.00.0030.0438.20
4.4.90.0000.0177.75
4.4.80.0070.0307.75
4.4.70.0000.0207.75
4.4.60.0000.0277.75
4.4.50.0000.0177.75
4.4.40.0030.0537.75
4.4.30.0000.0337.75
4.4.20.0000.0377.75
4.4.10.0030.0207.75
4.4.00.0000.0477.75
4.3.110.0030.0337.75
4.3.100.0030.0377.75
4.3.90.0000.0277.75
4.3.80.0030.0277.75
4.3.70.0000.0177.75
4.3.60.0030.0377.75
4.3.50.0000.0177.75
4.3.40.0000.0507.75
4.3.30.0000.0377.75
4.3.20.0000.0377.75
4.3.10.0000.0307.75
4.3.00.0030.0337.75

preferences:
45.8 ms | 401 KiB | 5 Q