3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait implementedBar { public function bar($a){ echo "a"; } } trait abstractBar { abstract protected function bar($a); } abstract class parentImplemented { use implementedBar; } class childAbstract extends parentImplemented { use abstractBar; } //what would happen if you copy/pasted the traits into their classes //the below classes would definitely cause an error /** abstract class parentImplemented { public function bar($a){ echo "a"; } } class childAbstract extends parentImplemented { abstract protected function bar($a); } **/ //below will just work, but we can't really see that implementedBar::bar is an implementation of abstractBar::bar //instead of it being a replacement, or abstractBar::bar just getting ignored echo "Example 1:".PHP_EOL; $b = new childAbstract; $b->bar([]); //////////////////////////////////// trait implementedBarTH { public function bar(array $a){ echo "a"; } } trait abstractBarTH { abstract protected function bar(int $a); } abstract class parentImplementedTH { use implementedBarTH; } class childAbstractTH extends parentImplementedTH { use abstractBarTH; } //again, a version with the traits copy/pasted into their classes //definitely will cause an error /** abstract class parentImplementedTH { public function bar(array $a){ echo "a"; } } class childAbstractTH extends parentImplementedTH { abstract protected function bar(int $a); } **/ //This will give us an error related to mismatched type hints. //This shows that the method in the trait used in the parent class is definitely //acting as an implementation of the abstract class from the trait used in the child class $b = new childAbstractTH; $b->bar([]); /*** You'll need to comment out 53-59, 80-81 in order to produce an error for the items below ***/ ////////////////////////////////////////////////////////////// class childBothTH { use abstractBarTH, implementedBarTH; } //a version with the traits copy/pasted into the class //definitely will cause an error /** class childBothTH { abstract protected function bar(int $a); public function bar(array $a){ echo "a"; } } **/ //This will give us an error related to mismatched type hints. //This shows that the method in the trait that was implemented is definitely //acting as an implementation of the abstract class from the other trait $b = new childBothTH; $b->bar([]);

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.0180.00318.31
8.3.50.0040.01116.54
8.3.40.0120.00318.51
8.3.30.0110.00418.63
8.3.20.0040.00419.01
8.3.10.0080.00023.65
8.3.00.0040.00420.67
8.2.180.0090.00618.54
8.2.170.0170.00322.96
8.2.160.0070.00722.15
8.2.150.0000.00824.18
8.2.140.0080.00024.66
8.2.130.0000.00819.77
8.2.120.0080.00026.35
8.2.110.0000.00921.04
8.2.100.0090.00317.78
8.2.90.0050.00317.63
8.2.80.0030.00617.97
8.2.70.0030.00517.93
8.2.60.0030.00618.17
8.2.50.0000.00818.10
8.2.40.0050.00319.34
8.2.30.0040.00419.32
8.2.20.0050.00318.29
8.2.10.0040.00418.04
8.2.00.0000.00917.63
8.1.280.0090.00925.92
8.1.270.0080.00022.20
8.1.260.0060.00326.35
8.1.250.0110.00428.09
8.1.240.0090.00022.62
8.1.230.0080.00417.83
8.1.220.0030.00617.74
8.1.210.0050.00318.77
8.1.200.0030.00617.25
8.1.190.0090.00017.23
8.1.180.0000.00818.10
8.1.170.0000.00918.50
8.1.160.0070.00418.88
8.1.150.0020.00518.82
8.1.140.0030.00322.18
8.1.130.0000.00720.00
8.1.120.0030.00917.53
8.1.110.0000.00817.48
8.1.100.0040.00317.38
8.1.90.0030.00617.46
8.1.80.0000.00817.45
8.1.70.0040.00417.33
8.1.60.0050.00317.49
8.1.50.0000.00817.50
8.1.40.0080.00017.48
8.1.30.0060.00317.66
8.1.20.0000.00717.55
8.1.10.0080.00017.62
8.1.00.0060.00317.39
8.0.300.0070.00318.77
8.0.290.0000.00916.75
8.0.280.0000.00718.49
8.0.270.0040.00416.88
8.0.260.0060.00018.44
8.0.250.0070.00017.00
8.0.240.0040.00416.98
8.0.230.0050.00216.96
8.0.220.0090.00016.89
8.0.210.0000.00716.98
8.0.200.0000.00717.04
8.0.190.0060.00317.02
8.0.180.0040.00416.98
8.0.170.0030.00616.85
8.0.160.0040.00416.96
8.0.150.0050.00216.88
8.0.140.0000.00816.93
8.0.130.0050.00013.42
8.0.120.0040.00416.95
8.0.110.0070.00016.91
8.0.100.0070.00016.92
8.0.90.0040.00417.04
8.0.80.0110.00716.96
8.0.70.0020.00516.86
8.0.60.0070.00016.91
8.0.50.0000.00716.89
8.0.30.0120.00917.04
8.0.20.0090.00917.40
8.0.10.0000.00717.13
8.0.00.0050.01416.75
7.4.330.0050.00015.55
7.4.320.0030.00316.65
7.4.300.0000.00716.43
7.4.290.0030.00316.59
7.4.280.0040.00416.44
7.4.270.0030.00316.61
7.4.260.0060.00016.58
7.4.250.0030.00316.38
7.4.240.0030.00316.61
7.4.230.0000.00716.50
7.4.220.0000.00816.30
7.4.210.0070.00716.59
7.4.200.0060.00316.71
7.4.160.0080.00816.50
7.4.140.0110.00817.86
7.4.130.0110.00916.61
7.4.120.0100.01016.52
7.4.110.0070.01416.54
7.4.100.0090.00916.62
7.4.90.0130.01016.47
7.4.80.0110.00719.39
7.4.70.0120.00916.52
7.4.60.0060.01016.66
7.4.50.0030.01316.44
7.4.40.0060.00916.41
7.4.00.0050.01115.05
7.3.330.0000.00613.36
7.3.320.0030.00313.38
7.3.310.0060.00316.34
7.3.300.0060.00016.24
7.3.290.0000.00616.29
7.3.280.0060.00816.37
7.3.260.0090.00916.60
7.3.240.0110.00716.44
7.3.230.0090.00916.56
7.3.210.0120.00616.42
7.3.200.0060.00916.46
7.3.190.0130.00416.29
7.3.180.0030.01416.30
7.3.170.0100.01316.33
7.3.160.0030.01216.34
7.3.120.0040.01114.79
7.3.110.0030.01414.46
7.3.100.0060.00914.70
7.3.90.0140.00015.11
7.3.80.0130.00314.65
7.3.70.0060.00314.65
7.3.60.0070.01014.94
7.3.50.0000.01014.64
7.3.40.0060.00614.93
7.3.30.0090.00614.73
7.3.20.0100.00316.64
7.3.10.0110.00316.75
7.3.00.0110.00316.77
7.2.330.0090.00916.61
7.2.320.0130.01016.88
7.2.310.0090.01216.64
7.2.300.0160.00316.68
7.2.290.0120.00616.59
7.2.250.0040.01115.26
7.2.240.0150.00315.06
7.2.230.0070.01014.84
7.2.220.0110.00315.16
7.2.210.0040.01515.13
7.2.200.0090.00615.04
7.2.190.0000.01415.05
7.2.180.0120.00614.78
7.2.170.0120.00315.09
7.2.110.0340.00714.84
7.2.100.0640.01014.65
7.2.90.0080.01214.69
7.2.80.0250.01114.56
7.2.70.0400.00714.78
7.2.60.0080.01115.13
7.2.50.0120.00615.08
7.2.40.0310.01015.19
7.2.30.0510.00314.68
7.2.20.0540.01314.79
7.2.10.0410.00014.89
7.2.00.0280.00714.72
7.1.330.0070.00715.57
7.1.320.0070.00415.57
7.1.310.0000.01915.96
7.1.300.0040.00715.68
7.1.290.0030.00615.65
7.1.280.0040.00815.40
7.1.270.0000.01015.64
7.1.260.0050.00515.67
7.1.230.0320.00713.85
7.1.220.0560.01313.99
7.1.210.0230.01313.97
7.1.200.0310.00613.88
7.1.190.0940.00313.90
7.1.180.0110.00313.69
7.1.170.0490.00713.70
7.1.160.0070.00713.78
7.1.150.0270.00313.76
7.1.140.0180.00913.62
7.1.130.0400.00913.59
7.1.120.0030.01013.80
7.1.110.0100.00713.55
7.1.100.0270.01213.93
7.1.90.0320.00913.57
7.1.80.0590.00713.63
7.1.70.0410.01013.67
7.1.60.0310.01531.72
7.1.50.0570.01231.93
7.1.40.0550.00931.41
7.1.30.0450.00931.61
7.1.20.0920.01231.86
7.1.10.0120.00913.39
7.1.00.0350.00313.78
5.6.380.0080.00514.32

preferences:
69.35 ms | 401 KiB | 5 Q