3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* 10 common antipatterns and things that make your PHP code smell I've jotted down easy ways to identify code that is probably written by a novice/junior/fresher PHP developer. Check your projects for these sins. 1. @ -- the "STFU operator" If you are using error suppression, you are probably not handling data in the most professional way. https://stackoverflow.com/a/960288/2943403 2. if (isset($v) && !empty($v) ) { ... } It is never necessary to do both. https://stackoverflow.com/a/4559976/2943403 3. $newString = "" . $v1 . $v2; -- prepending an empty string for no reason. Appending an empty string is an old-skool or hacky way of ensuring that a value is cast as string type. If a value actually should be type cast, then PHP has better, explicit techniques. Most of the time I see this technique, the values would be cast as a string due to other factors anyhow. This technique is most commonly found in code generated by or copied from tutorials from developers in Middle East regions. 4. echo sprintf() If you want to printf() something, just do it. Don't pass the job to echo to do. 5. /[A-Za-z]+/i , /\D+/s , /.+/m , /\w+:\w+/x , /\R/simUgx -- Meaningless regex flags It is an instant giveaway that you don't understand regex when you add pattern modifiers that have absolutely no impact on your pattern. If you don't know why these examples are wrong/silly, learn what each flag does. Don't just pile a bunch of flags up for no reason! Don't copy patterns into your project if you don't know how they work. 6. switch(true) { ... } -- multi-evaluation switch blocks The ONLY thing good about switch blocks is that they perform a single-evaluation. Feeding a static value to the switch means that each branch will need to be evaluated. You might as well just use an if-elseif-else block because the performance will be the same and the syntax will probably be more brief. Furthermore, now that we have match(), there are very few reasons to drag out a switch block. 7. Generating HTML or querying the database in the controller. There are many ways that developers can abuse controllers in an MVC project. These are just two that I find irritatingly common and relatively easy to fix/avoid. Learn to use views and models properly. 8. md5() being any part of a password encryption script. Please, no. Not even if you are offering a basic programming tutorial. Never teach new developers things that they will need to unlearn. 9. Injecting user-supplied data directly into an SQL string. Many professional developers are using frameworks which abstract this basic technique away, but new developers who are learning outside of a framework often write attack vectors into their code by not properly using prepared statements. 10. $condition ? $result = "true" : $result = "false"; -- shorthand ternaries that don't return anything. Use ternaries properly or write an if-else block. $result = $condition ? "true" : "false"; */

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.5.30.0100.00819.57
8.5.20.0110.00717.82
8.5.10.0090.00919.63
8.5.00.0130.01019.71
8.4.180.0100.01120.55
8.4.170.0110.00922.08
8.4.160.0120.00921.43
8.4.150.0070.00516.78
8.4.140.0140.00817.59
8.4.130.0080.01117.60
8.4.120.0070.00226.03
8.4.110.0130.00722.45
8.4.100.0130.00718.95
8.4.90.0100.00818.39
8.4.80.0090.00517.57
8.4.70.0220.00417.33
8.4.60.0140.00717.84
8.4.50.0170.00418.78
8.4.40.0170.00417.33
8.4.30.0210.00518.98
8.4.20.0190.00419.08
8.4.10.0160.00419.39
8.3.300.0120.00920.09
8.3.290.0110.00920.80
8.3.280.0120.00818.22
8.3.270.0110.00816.21
8.3.260.0050.00716.52
8.3.250.0090.00918.83
8.3.240.0100.00817.17
8.3.230.0130.00616.40
8.3.220.0180.00316.59
8.3.210.0150.00316.32
8.3.200.0150.00616.49
8.3.190.0110.00416.74
8.3.180.0110.00516.52
8.3.170.0130.00816.75
8.3.160.0170.00417.04
8.3.150.0180.00717.59
8.3.140.0130.00616.59
8.3.130.0130.00516.25
8.3.120.0120.00617.20
8.3.110.0120.00517.84
8.3.100.0190.00618.79
8.3.90.0150.00719.77
8.3.80.0200.00416.83
8.3.70.0230.00516.86
8.3.60.0180.00817.09
8.3.50.0150.00516.41
8.3.40.0170.00718.81
8.3.30.0090.00918.16
8.3.20.0110.00819.63
8.3.10.0130.00821.59
8.3.00.0110.00522.66
8.2.300.0120.00922.07
8.2.290.0130.00520.11
8.2.280.0100.00417.69
8.2.270.0130.00816.75
8.2.260.0170.00417.29
8.2.250.0150.00517.49
8.2.240.0170.00317.88
8.2.230.0180.00518.45
8.2.220.0160.00223.35
8.2.210.0130.00919.66
8.2.200.0190.00316.93
8.2.190.0170.00616.29
8.2.180.0180.00416.27
8.2.170.0170.00717.83
8.2.160.0180.00719.39
8.2.150.0190.00620.05
8.2.140.0160.00621.66
8.2.130.0140.00622.68
8.2.120.0120.00321.85
8.2.110.0150.00621.91
8.2.100.0140.00421.37
8.2.90.0130.00721.49
8.2.80.0150.00521.49
8.2.70.0140.00521.49
8.2.60.0130.00621.37
8.2.50.0120.00721.49
8.2.40.0150.00321.48
8.2.30.0100.00521.50
8.2.20.0130.00321.44
8.2.10.0080.00721.46
8.2.00.0120.00421.47
8.1.340.0110.00817.61
8.1.330.0160.01221.72
8.1.320.0130.00515.99
8.1.310.0170.00616.18
8.1.300.0160.00416.54
8.1.290.0160.00516.87
8.1.280.0180.00519.30
8.1.270.0150.00721.54
8.1.260.0140.00621.92
8.1.250.0110.00721.94
8.1.240.0110.00521.43
8.1.230.0100.00621.76
8.1.220.0130.00321.40
8.1.210.0100.00621.42
8.1.200.0100.00521.41
8.1.190.0130.00121.33
8.1.180.0110.00521.37
8.1.170.0080.00821.38
8.1.160.0130.00321.37
8.1.150.0120.00221.39
8.1.140.0080.00421.34
8.1.130.0100.00321.42
8.1.120.0100.00321.37
8.1.110.0100.00321.35
8.1.100.0100.00421.38
8.1.90.0100.00421.38
8.1.80.0110.00321.43
8.1.70.0100.00521.46
8.1.60.0100.00621.45
8.1.50.0120.00421.42
8.1.40.0120.00321.44
8.1.30.0100.00621.50
8.1.20.0130.00221.44
8.1.10.0120.00421.43
8.1.00.0110.00621.36
8.0.300.0100.00621.17
8.0.290.0130.00521.17
8.0.280.0160.00421.15
8.0.270.0140.00221.15
8.0.260.0120.00421.17
8.0.250.0090.00421.21
8.0.240.0120.00621.19
8.0.230.0110.00421.20
8.0.220.0100.00621.19
8.0.210.0110.00521.17
8.0.200.0110.00421.16
8.0.190.0100.00521.15
8.0.180.0100.00521.20
8.0.170.0130.00421.18
8.0.160.0120.00521.20
8.0.150.0130.00421.17
8.0.140.0120.00421.19
8.0.130.0130.00421.15
8.0.120.0120.00521.19
8.0.110.0090.00621.17
8.0.100.0120.00321.15
8.0.90.0140.00321.12
8.0.80.0110.00421.18
8.0.70.0120.00421.16
8.0.60.0120.00321.17
8.0.50.0140.00521.15
8.0.30.0120.00521.15
8.0.20.0110.00521.18
8.0.10.0130.00421.23
8.0.00.0140.00216.33
7.4.330.0120.00516.34
7.4.320.0140.00316.11
7.4.300.0130.00616.12
7.4.290.0120.00416.23
7.4.280.0100.00516.21
7.4.270.0140.00216.07
7.4.260.0130.00216.25
7.4.250.0150.00316.13
7.4.240.0100.00616.33
7.4.230.0120.00416.12
7.4.220.0120.00515.94
7.4.210.0130.00316.00
7.4.200.0110.00516.24
7.4.190.0130.00415.78
7.4.180.0110.00516.24
7.4.160.0150.00115.95
7.4.150.0110.00615.92
7.4.140.0110.00716.03
7.4.130.0150.00115.70
7.4.120.0160.00115.81
7.4.110.0140.00316.04
7.4.100.0140.00115.82
7.4.90.0150.00215.89
7.4.80.0130.00315.97
7.4.70.0110.00415.97
7.4.60.0120.00316.16
7.4.50.0110.00416.00
7.4.40.0120.00215.96
7.4.30.0150.00215.94
7.4.20.0110.00416.09
7.4.10.0110.00416.13
7.4.00.0130.00515.74
7.3.330.0140.00115.77
7.3.320.0140.00116.04
7.3.310.0140.00215.88
7.3.300.0090.00715.92
7.3.290.0140.00315.66
7.3.280.0120.00415.77
7.3.270.0120.00315.86
7.3.260.0110.00315.84
7.3.250.0140.00215.54
7.3.240.0150.00215.78
7.3.230.0110.00415.59
7.3.220.0120.00515.56
7.3.210.0140.00415.71
7.3.200.0140.00115.88
7.3.190.0130.00515.81
7.3.180.0140.00315.70
7.3.170.0140.00215.82
7.3.160.0110.00515.98
7.3.150.0150.00215.67
7.3.140.0120.00515.99
7.3.130.0120.00415.59
7.3.120.0120.00315.74
7.3.110.0120.00315.48
7.3.100.0110.00315.68
7.3.90.0120.00216.18
7.3.80.0120.00316.03
7.3.70.0120.00315.99
7.3.60.0100.00516.05
7.3.50.0130.00315.93
7.3.40.0110.00416.00
7.3.30.0120.00416.09
7.3.20.0150.00217.93
7.3.10.0070.00317.64
7.3.00.0080.00217.95
7.2.340.0120.00316.00
7.2.330.0110.00415.90
7.2.320.0140.00315.86
7.2.310.0140.00315.94
7.2.300.0150.00615.59
7.2.290.0170.00015.79
7.2.280.0120.00315.93
7.2.270.0120.00316.03
7.2.260.0130.00515.84
7.2.250.0120.00315.62
7.2.240.0140.00215.80
7.2.230.0120.00415.82
7.2.220.0130.00315.79
7.2.210.0150.00215.96
7.2.200.0160.00016.18
7.2.190.0140.00415.80
7.2.180.0140.00515.79
7.2.170.0120.00415.90
7.2.160.0140.00516.04
7.2.150.0150.00417.73
7.2.140.0140.00418.05
7.2.130.0140.00518.09
7.2.120.0120.00617.97
7.2.110.0130.00517.90
7.2.100.0110.00517.80
7.2.90.0190.00117.71
7.2.80.0140.00317.78
7.2.70.0140.00517.99
7.2.60.0130.00617.87
7.2.50.0150.00417.86
7.2.40.0140.00318.02
7.2.30.0120.00518.16
7.2.20.0190.00218.19
7.2.10.0170.00318.07
7.2.00.0140.00518.16
7.1.330.0160.00116.70
7.1.320.0180.00216.48
7.1.310.0150.00516.49
7.1.300.0150.00316.83
7.1.290.0160.00216.79
7.1.280.0110.00517.05
7.1.270.0160.00016.93
7.1.260.0150.00216.92
7.1.250.0150.00216.86
7.1.240.0110.00416.60
7.1.230.0160.00316.92
7.1.220.0130.00317.04
7.1.210.0110.00316.77
7.1.200.0130.00417.17
7.1.190.0140.00216.65
7.1.180.0140.00016.86
7.1.170.0130.00516.70
7.1.160.0150.00216.80
7.1.150.0140.00316.61
7.1.140.0130.00516.89
7.1.130.0140.00316.67
7.1.120.0150.00316.70
7.1.110.0130.00216.73
7.1.100.0140.00316.60
7.1.90.0110.00516.65
7.1.80.0100.00416.90
7.1.70.0120.00416.68
7.1.60.0150.00217.01
7.1.50.0110.00516.95
7.1.40.0140.00216.81
7.1.30.0120.00317.16
7.1.20.0120.00316.78
7.1.10.0140.00317.05
7.1.00.0110.00616.74
7.0.330.0150.00316.49
7.0.320.0270.00316.71
7.0.310.0140.00116.58
7.0.300.0160.00616.37
7.0.290.0070.00516.66
7.0.280.0110.00316.52
7.0.270.0110.00316.55
7.0.260.0110.00316.43
7.0.250.0100.00416.55
7.0.240.0130.00516.74
7.0.230.0140.00216.96
7.0.220.0130.00516.46
7.0.210.0150.00116.57
7.0.200.0150.00116.41
7.0.190.0100.00516.61
7.0.180.0170.00216.30
7.0.170.0140.00416.77
7.0.160.0110.00716.65
7.0.150.0150.00316.73
7.0.140.0140.00316.39
7.0.130.0100.00516.63
7.0.120.0140.00316.52
7.0.110.0120.00316.38
7.0.100.0170.00016.75
7.0.90.0140.00416.29
7.0.80.0090.00716.29
7.0.70.0120.00316.63
7.0.60.0110.00716.45
7.0.50.0150.00216.44
7.0.40.0100.00616.71
7.0.30.0110.00516.41
7.0.20.0110.00316.46
7.0.10.0120.00316.62
7.0.00.0150.00216.44
5.6.400.0080.00615.55
5.6.390.0090.00615.44
5.6.380.0120.00515.18
5.6.370.0150.00315.56
5.6.360.0130.00615.43
5.6.350.0130.00515.55
5.6.340.0150.00415.57
5.6.330.0140.00515.54
5.6.320.0130.00515.54
5.6.310.0130.00315.54
5.6.300.0180.00215.24
5.6.290.0130.00515.32
5.6.280.0100.00415.27
5.6.270.0110.00515.16
5.6.260.0110.00615.44
5.6.250.0150.00115.47
5.6.240.0160.00515.56
5.6.230.0140.00415.60
5.6.220.0110.00615.52
5.6.210.0120.00415.71
5.6.200.0100.00715.38
5.6.190.0100.00515.57
5.6.180.0130.00415.12
5.6.170.0140.00315.49
5.6.160.0120.00415.43
5.6.150.0110.00215.47
5.6.140.0100.00415.42
5.6.130.0110.00615.59
5.6.120.0100.00515.52
5.6.110.0110.00415.34
5.6.100.0120.00315.34
5.6.90.0120.00215.18
5.6.80.0110.00215.34
5.6.70.0100.00515.43
5.6.60.0120.00215.21
5.6.50.0100.00415.29
5.6.40.0130.00315.26
5.6.30.0140.00215.33
5.6.20.0110.00415.36
5.6.10.0100.00415.45
5.6.00.0110.00515.33
5.5.380.0130.00315.26
5.5.370.0120.00115.61
5.5.360.0150.00115.32
5.5.350.0100.00415.15
5.5.340.0120.00215.24
5.5.330.0090.00515.41
5.5.320.0090.00515.16
5.5.310.0090.00615.29
5.5.300.0120.00415.21
5.5.290.0130.00215.30
5.5.280.0130.00215.08
5.5.270.0090.00515.11
5.5.260.0110.00415.07
5.5.250.0130.00115.39
5.5.240.0110.00415.39
5.5.230.0110.00415.49
5.5.220.0100.00515.46
5.5.210.0110.00315.39
5.5.200.0110.00315.23
5.5.190.0110.00315.11
5.5.180.0100.00615.11
5.5.170.0100.00315.11
5.5.160.0100.00315.34
5.5.150.0100.00315.14
5.5.140.0110.00415.31
5.5.130.0090.00415.27
5.5.120.0100.00315.01
5.5.110.0110.00215.02
5.5.100.0120.00215.38
5.5.90.0100.00415.08
5.5.80.0110.00315.30
5.5.70.0140.00315.32
5.5.60.0130.00215.30
5.5.50.0160.00115.07
5.5.40.0110.00415.04
5.5.30.0120.00415.29
5.5.20.0100.00415.64
5.5.10.0100.00315.27
5.5.00.0090.00515.39
5.4.450.0080.00214.73
5.4.440.0060.00514.73
5.4.430.0090.00214.73
5.4.420.0070.00414.73
5.4.410.0100.00114.73
5.4.400.0070.00414.73
5.4.390.0060.00514.73
5.4.380.0070.00314.73
5.4.370.0070.00514.73
5.4.360.0080.00214.73
5.4.350.0090.00414.73
5.4.340.0080.00214.73
5.4.330.0080.00214.73
5.4.320.0070.00414.73
5.4.310.0100.00114.73
5.4.300.0090.00314.73
5.4.290.0080.00214.73
5.4.280.0080.00314.73
5.4.270.0090.00114.73
5.4.260.0100.00214.73
5.4.250.0100.00114.73
5.4.240.0100.00114.73
5.4.230.0080.00214.73
5.4.220.0090.00214.73
5.4.210.0090.00214.73
5.4.200.0110.00114.73
5.4.190.0080.00214.73
5.4.180.0080.00414.73
5.4.170.0100.00014.73
5.4.160.0110.00114.73
5.4.150.0080.00314.73
5.4.140.0090.00214.73
5.4.130.0070.00414.73
5.4.120.0080.00314.73
5.4.110.0070.00414.73
5.4.100.0080.00214.73
5.4.90.0090.00214.73
5.4.80.0080.00314.73
5.4.70.0080.00214.73
5.4.60.0090.00214.73
5.4.50.0100.00114.73
5.4.40.0060.00514.73
5.4.30.0100.00214.73
5.4.20.0090.00314.73
5.4.10.0100.00114.73
5.4.00.0090.00314.73
5.3.290.0080.00314.73
5.3.280.0090.00214.73
5.3.270.0080.00214.73
5.3.260.0070.00314.73
5.3.250.0090.00214.73
5.3.240.0100.00214.73
5.3.230.0110.00314.73
5.3.220.0100.00214.73
5.3.210.0090.00114.73
5.3.200.0070.00314.73
5.3.190.0100.00214.73
5.3.180.0100.00314.73
5.3.170.0080.00314.73
5.3.160.0080.00214.73
5.3.150.0070.00414.73
5.3.140.0090.00214.73
5.3.130.0070.00414.73
5.3.120.0070.00314.73
5.3.110.0100.00014.73
5.3.100.0060.00514.73
5.3.90.0090.00214.73
5.3.80.0090.00214.73
5.3.70.0070.00414.73
5.3.60.0080.00214.73
5.3.50.0090.00214.73
5.3.40.0070.00414.73
5.3.30.0100.00014.73
5.3.20.0080.00214.73
5.3.10.0070.00414.73
5.3.00.0100.00114.73
5.2.170.0060.00314.73
5.2.160.0050.00414.73
5.2.150.0070.00114.73
5.2.140.0060.00214.73
5.2.130.0080.00214.73
5.2.120.0050.00414.73
5.2.110.0080.00114.73
5.2.100.0060.00314.73
5.2.90.0060.00314.73
5.2.80.0070.00314.73
5.2.70.0050.00414.73
5.2.60.0070.00214.73
5.2.50.0080.00314.73
5.2.40.0050.00314.73
5.2.30.0090.00114.73
5.2.20.0070.00414.73
5.2.10.0060.00414.73
5.2.00.0070.00114.73
5.1.60.0060.00214.73
5.1.50.0060.00214.73
5.1.40.0060.00214.73
5.1.30.0060.00214.73
5.1.20.0050.00314.73
5.1.10.0070.00114.73
5.1.00.0100.00314.73
5.0.50.0070.00414.73
5.0.40.0040.00414.73
5.0.30.0030.00414.73
5.0.20.0020.00414.73
5.0.10.0050.00214.73
5.0.00.0050.00114.73
4.4.90.0030.00114.73
4.4.80.0030.00014.73
4.4.70.0030.00114.73
4.4.60.0030.00014.73
4.4.50.0040.00014.73
4.4.40.0040.00014.73
4.4.30.0040.00014.73
4.4.20.0030.00114.73
4.4.10.0030.00014.73
4.4.00.0020.00114.73
4.3.110.0030.00014.73
4.3.100.0040.00014.73
4.3.90.0020.00114.73
4.3.80.0040.00014.73
4.3.70.0040.00014.73
4.3.60.0020.00214.73
4.3.50.0030.00114.73
4.3.40.0030.00014.73
4.3.30.0040.00014.73
4.3.20.0030.00014.73
4.3.10.0010.00214.73
4.3.00.0030.00114.73

preferences:
62.65 ms | 2639 KiB | 5 Q