3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Can I create an alias for an entire namespace in PHP? * * class_alias() on spl_autoload_class() for namespace prefix * * @link https://stackoverflow.com/a/74236530/367456 * @author hakre <https://hakre.wordpress.com/> */ namespace { // warning instead of exception to simulate testing mode on 3v4l.org, // in development it should throw so that code touching path is // updated. ini_set('assert.exception', '0'); spl_autoload_register( static function (string $class_name) { static $old = 'My\\Old\\Lib\\Name\\'; static $new = 'My\\Tiger\\Lib\\Name\\'; // only operate on the old namespace if (0 !== strpos($class_name, $old)) { return; } $new_name = str_replace($old, $new, $class_name); assert(false, "old namespace in use: $class_name"); class_alias($new_name, $class_name); $exists = class_exists($new_name); assert($exists, "aliasing old namespace failed for class: $class_name"); }, $throw = true, /* throw when registering fails */ $prepend = false /* only alias at fall-through */ ); } namespace My\Tiger\Lib\Name\Module { class Boring { } } namespace My\Old\Lib\Name { use My\Old\Lib\Name\Module\Boring; $boring = new Boring(); assert($boring); assert($boring instanceof Module\Boring); var_dump(get_class($boring)); }

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.4.140.0130.00817.62
8.4.130.0040.00517.79
8.4.120.0110.00924.02
8.4.110.0120.00821.74
8.4.100.0090.00219.16
8.4.90.0130.00518.88
8.4.80.0070.00118.78
8.4.70.0120.00818.01
8.4.60.0110.00618.91
8.4.50.0030.00519.65
8.4.40.0090.00017.89
8.4.30.0190.00320.57
8.4.20.0100.00017.78
8.4.10.0170.00323.49
8.3.260.0100.00917.26
8.3.250.0070.00119.16
8.3.240.0120.00617.37
8.3.230.0060.00216.90
8.3.220.0120.00719.09
8.3.210.0110.00816.77
8.3.200.0100.00916.62
8.3.190.0060.00416.87
8.3.180.0110.00816.75
8.3.170.0080.01120.68
8.3.160.0110.00717.29
8.3.150.0130.00617.35
8.3.140.0060.00318.66
8.3.130.0030.00516.77
8.3.120.0040.00420.83
8.3.110.0070.00418.70
8.3.100.0060.00318.49
8.3.90.0070.00726.77
8.3.80.0030.00618.56
8.3.70.0060.01016.63
8.3.60.0000.01518.27
8.3.50.0040.01120.18
8.3.40.0040.01120.32
8.3.30.0080.00818.79
8.3.20.0060.00324.18
8.3.10.0040.00424.66
8.3.00.0080.00026.16
8.2.290.0130.00820.32
8.2.280.0080.00518.71
8.2.270.0060.00817.06
8.2.260.0150.00320.69
8.2.250.0000.00916.97
8.2.240.0090.00018.82
8.2.230.0000.00820.94
8.2.220.0060.00324.06
8.2.210.0040.00426.77
8.2.200.0030.00718.41
8.2.190.0150.00318.41
8.2.180.0090.00625.92
8.2.170.0040.01119.04
8.2.160.0030.01022.96
8.2.150.0000.00925.66
8.2.140.0040.00424.66
8.2.130.0110.00426.16
8.2.120.0150.00326.16
8.2.110.0080.00322.28
8.2.100.0080.00419.64
8.2.90.0000.00817.63
8.2.80.0000.00817.97
8.2.70.0040.00417.80
8.2.60.0000.00818.03
8.2.50.0000.00818.10
8.2.40.0080.00019.48
8.2.30.0000.00919.16
8.2.20.0060.00519.04
8.2.10.0040.00417.99
8.2.00.0050.00319.38
8.1.330.0060.01322.31
8.1.320.0080.01116.55
8.1.310.0040.00716.93
8.1.300.0030.00718.41
8.1.290.0030.00630.84
8.1.280.0110.00325.92
8.1.270.0080.00024.66
8.1.260.0110.00726.35
8.1.250.0050.00328.09
8.1.240.0090.00023.84
8.1.230.0040.00821.03
8.1.220.0000.00817.74
8.1.210.0000.01218.77
8.1.200.0000.01317.34
8.1.190.0090.00017.25
8.1.180.0000.00818.10
8.1.170.0040.00418.64
8.1.160.0000.00718.85
8.1.150.0000.00718.70
8.1.140.0050.00317.52
8.1.130.0030.00318.81
8.1.120.0080.00817.48
8.1.110.0080.00817.41
8.1.100.0080.00817.46
8.1.90.0050.01017.47
8.1.80.0080.00817.42
8.1.70.0100.00717.37
8.1.60.0140.00517.54
8.1.50.0140.00517.48
8.1.40.0130.00617.58
8.1.30.0090.00917.65
8.1.20.0140.00717.62
8.1.10.0150.00317.57
8.1.00.0140.00617.43
8.0.300.0000.00720.04
8.0.290.0050.00316.75
8.0.280.0030.00318.45
8.0.270.0000.00717.26
8.0.260.0030.00318.37
8.0.250.0040.00416.95
8.0.240.0160.00016.88
8.0.230.0150.00016.91
8.0.220.0120.00416.91
8.0.210.0070.00716.96
8.0.200.0120.00416.91
8.0.190.0000.01416.95
8.0.180.0120.00416.95
8.0.170.0000.01416.87
8.0.160.0150.00216.82
8.0.150.0000.01416.88
8.0.140.0120.00216.93
8.0.130.0100.00616.82
8.0.120.0150.00016.87
8.0.110.0090.00616.86
8.0.100.0150.00016.98
8.0.90.0070.00716.89
8.0.80.0090.00616.91
8.0.70.0110.00616.89
8.0.60.0100.00516.81
8.0.50.0050.00916.85
8.0.30.0100.00416.77
8.0.20.0130.00316.87
8.0.10.0080.00816.98
7.4.330.0050.00015.55
7.4.320.0160.00016.48
7.4.300.0080.00916.56
7.4.290.0060.00916.53
7.4.280.0120.00416.63
7.4.270.0150.00316.43
7.4.260.0090.00616.52
7.4.250.0090.00916.49
7.4.240.0140.00016.52
7.4.230.0100.00616.63
7.4.220.0080.00816.50
7.4.210.0150.00016.50
7.4.200.0130.00316.51
7.4.190.0130.00016.59
7.4.180.0030.01016.57
7.4.160.0070.00416.65
7.4.150.0110.00016.48
7.4.140.0070.00416.47
7.4.130.0080.00216.32
7.4.120.0070.00515.97
7.4.110.0080.00416.34
7.4.100.0040.00716.32
7.4.90.0090.00016.46
7.4.80.0070.00415.89
7.4.70.0040.00716.35
7.4.60.0080.00316.05
7.4.50.0000.01016.18
7.4.40.0080.00316.29
7.4.30.0070.00416.16
7.4.20.0070.00316.14
7.4.10.0040.00616.54
7.4.00.0070.00416.30
7.3.00.0070.00617.51
7.2.340.0050.00617.53

preferences:
106.57 ms | 403 KiB | 5 Q