3v4l.org

run code in 300+ PHP versions simultaneously
<?php set_error_handler(array('My_ToStringFixer', 'errorHandler')); error_reporting(E_ALL | E_STRICT); class My_ToStringFixer { protected static $_toStringException; public static function errorHandler($errorNumber, $errorMessage, $errorFile, $errorLine) { if (isset(self::$_toStringException)) { $exception = self::$_toStringException; // Always unset '_toStringException', we don't want a straggler to be found later if something came between the setting and the error self::$_toStringException = null; if (preg_match('~^Method .*::__toString\(\) must return a string value$~', $errorMessage)) throw $exception; } return false; } public static function throwToStringException($exception) { // Should not occur with prescribed usage, but in case of recursion: clean out exception, return a valid string, and weep if (isset(self::$_toStringException)) { self::$_toStringException = null; return ''; } self::$_toStringException = $exception; return null; } } class My_Class { public function doComplexStuff() { throw new Exception('Oh noes!'); } public function __toString() { try { // do your complex thing which might trigger an exception return $this->doComplexStuff(); } catch (Exception $e) { // The 'return' is required to trigger the trick return My_ToStringFixer::throwToStringException($e); } } } $x = new My_Class(); try { echo $x; } catch (Exception $e) { echo 'Caught Exception! : '. $e; }

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.0150.00618.55
8.3.50.0100.00921.03
8.3.40.0070.00718.76
8.3.30.0100.00319.07
8.3.20.0040.00420.34
8.3.10.0080.00023.65
8.3.00.0050.00319.50
8.2.180.0070.00718.29
8.2.170.0110.00422.96
8.2.160.0110.00320.15
8.2.150.0040.00424.18
8.2.140.0030.00624.66
8.2.130.0030.00626.16
8.2.120.0070.00022.21
8.2.110.0030.00621.10
8.2.100.0040.00817.72
8.2.90.0030.00517.84
8.2.80.0000.00817.97
8.2.70.0000.00917.75
8.2.60.0050.00318.16
8.2.50.0040.00418.07
8.2.40.0050.00318.22
8.2.30.0030.00518.10
8.2.20.0070.00017.86
8.2.10.0050.00218.11
8.2.00.0030.00517.83
8.1.280.0070.00725.92
8.1.270.0080.00023.96
8.1.260.0040.00426.35
8.1.250.0000.00728.09
8.1.240.0090.00022.70
8.1.230.0090.00320.95
8.1.220.0040.00417.74
8.1.210.0080.00018.77
8.1.200.0060.00317.35
8.1.190.0000.00817.23
8.1.180.0060.00318.10
8.1.170.0000.00820.43
8.1.160.0000.00821.96
8.1.150.0050.00218.85
8.1.140.0040.00417.52
8.1.130.0000.00717.80
8.1.120.0040.00417.44
8.1.110.0030.00417.55
8.1.100.0040.00417.48
8.1.90.0080.00017.35
8.1.80.0030.00317.51
8.1.70.0030.00317.50
8.1.60.0120.00317.62
8.1.50.0040.00417.54
8.1.40.0070.00017.51
8.1.30.0050.00317.62
8.1.20.0080.00017.71
8.1.10.0050.00317.55
8.1.00.0060.00317.57
8.0.300.0090.00319.69
8.0.290.0040.00416.88
8.0.280.0040.00418.54
8.0.270.0030.00517.20
8.0.260.0070.00018.45
8.0.250.0000.00717.07
8.0.240.0000.00717.08
8.0.230.0040.00416.90
8.0.220.0070.00016.93
8.0.210.0030.00316.88
8.0.200.0070.00017.07
8.0.190.0040.00417.03
8.0.180.0040.00416.94
8.0.170.0040.00416.91
8.0.160.0030.00317.05
8.0.150.0070.00016.82
8.0.140.0080.00016.88
8.0.130.0030.00313.41
8.0.120.0000.00916.92
8.0.110.0030.00517.02
8.0.100.0000.00717.01
8.0.90.0040.00416.95
8.0.80.0060.01016.95
8.0.70.0000.00716.88
8.0.60.0000.00716.97
8.0.50.0000.00817.01
8.0.30.0180.00017.22
8.0.20.0140.00717.40
8.0.10.0040.00416.99
8.0.00.0070.01016.85
7.4.330.0030.00315.02
7.4.320.0000.00616.68
7.4.300.0030.00316.51
7.4.290.0030.00316.45
7.4.280.0030.00316.54
7.4.270.0000.00716.57
7.4.260.0000.00816.50
7.4.250.0030.00516.66
7.4.240.0020.00516.58
7.4.230.0040.00416.72
7.4.220.0100.00716.70
7.4.210.0040.01116.73
7.4.200.0070.00016.45
7.4.160.0040.01216.59
7.4.150.0170.01017.40
7.4.140.0080.01017.86
7.4.130.0120.00616.62
7.4.120.0100.01016.51
7.4.110.0090.00916.71
7.4.100.0090.00916.59
7.4.90.0120.00316.53
7.4.80.0030.01519.39
7.4.70.0050.01416.48
7.4.60.0130.00316.60
7.4.50.0060.00316.49
7.4.40.0110.00616.68
7.4.30.0070.01416.45
7.4.00.0090.00815.08
7.3.330.0030.00513.52
7.3.320.0000.00513.57
7.3.310.0000.00716.73
7.3.300.0040.00416.55
7.3.290.0050.00916.53
7.3.280.0080.00816.65
7.3.270.0180.00517.40
7.3.260.0100.00616.71
7.3.250.0040.01416.55
7.3.240.0030.01516.88
7.3.230.0120.00616.76
7.3.210.0110.00716.71
7.3.200.0100.00719.39
7.3.190.0040.01416.61
7.3.180.0120.00316.79
7.3.170.0100.00616.68
7.3.160.0000.02116.59
7.3.120.0030.01314.86
7.3.110.0110.00714.94
7.3.100.0030.00615.08
7.3.90.0100.00715.35
7.3.80.0030.00615.30
7.3.70.0060.01015.17
7.3.60.0090.00615.19
7.3.50.0060.00615.02
7.3.40.0060.00914.97
7.3.30.0030.01014.96
7.3.20.0060.00316.93
7.3.10.0120.00416.85
7.3.00.0070.00417.04
7.2.330.0130.00616.88
7.2.320.0070.01016.95
7.2.310.0110.00616.70
7.2.300.0090.00916.95
7.2.290.0100.01416.79
7.2.250.0130.00715.28
7.2.240.0120.00815.28
7.2.230.0080.01115.06
7.2.220.0100.00015.35
7.2.210.0150.00015.11
7.2.200.0000.00915.25
7.2.190.0030.01115.25
7.2.180.0000.01015.16
7.2.170.0040.01415.30
7.2.60.0030.01316.90
7.2.00.0070.00719.62
7.1.330.0040.01216.21
7.1.320.0030.00716.01
7.1.310.0070.00715.70
7.1.300.0000.01616.13
7.1.290.0030.00815.97
7.1.280.0030.00915.93
7.1.270.0000.01116.10
7.1.260.0150.00016.02
7.1.200.0040.00815.98
7.1.100.0040.00818.31
7.1.70.0000.00717.09
7.1.60.0030.02219.32
7.1.50.0190.01635.09
7.1.00.0030.07722.50
7.0.200.1200.00415.05
7.0.140.0070.07021.94
7.0.100.0000.04719.92
7.0.90.0000.04319.93
7.0.80.0070.03719.90
7.0.70.0000.05319.93
7.0.60.0070.04319.89
7.0.50.0070.04020.23
7.0.40.0000.08720.15
7.0.30.0030.08320.08
7.0.20.0070.08320.04
7.0.10.0030.04720.13
7.0.00.0170.06720.17
5.6.280.0100.06720.83
5.6.250.0000.04320.68
5.6.240.0100.05320.68
5.6.230.0030.04320.64
5.6.220.0030.04320.66
5.6.210.0130.03720.47
5.6.200.0030.04321.00
5.6.190.0100.03721.07
5.6.180.0100.05320.97
5.6.170.0100.09321.14
5.6.160.0030.08321.03
5.6.150.0070.07021.05
5.6.140.0200.08321.02
5.6.130.0100.08321.04
5.6.120.0100.08321.07
5.6.110.0130.08021.07
5.6.100.0000.06320.99
5.6.90.0100.08021.00
5.6.80.0070.07720.47
5.6.70.0100.05020.52
5.6.60.0070.06320.40
5.6.50.0170.07020.47
5.6.40.0130.07720.42
5.6.30.0100.04320.37
5.6.20.0070.07020.37
5.6.10.0130.07720.37
5.6.00.0130.05020.37
5.5.380.0030.04320.35
5.5.370.0070.04020.50
5.5.360.0070.03720.35
5.5.350.0000.04320.41
5.5.340.0070.03720.64
5.5.330.0030.04320.94
5.5.320.0030.07720.94
5.5.310.0100.07320.65
5.5.300.0030.08020.79
5.5.290.0100.07720.89
5.5.280.0130.06320.79
5.5.270.0070.05020.62
5.5.260.0030.08020.78
5.5.250.0100.04720.45
5.5.240.0030.08020.22
5.5.230.0100.06320.20
5.5.220.0070.07020.32
5.5.210.0000.07020.26
5.5.200.0130.07020.17
5.5.190.0070.07720.20
5.5.180.0030.08320.16
5.5.160.0130.04720.13
5.5.150.0100.06020.18
5.5.140.0070.07020.09
5.5.130.0070.04320.00
5.5.120.0100.04020.28
5.5.110.0070.06720.18
5.5.100.0130.07720.17
5.5.90.0070.05320.18
5.5.80.0100.04019.98
5.5.70.0030.08020.07
5.5.60.0100.07319.95
5.5.50.0000.05320.16
5.5.40.0100.07020.07
5.5.30.0130.07320.05
5.5.20.0030.08320.01
5.5.10.0070.08020.04
5.5.00.0070.08720.09
5.4.450.0000.05019.42
5.4.440.0030.04319.20
5.4.430.0130.07019.44
5.4.420.0030.07719.48
5.4.410.0100.03719.36
5.4.400.0100.08019.05
5.4.390.0100.04019.12
5.4.380.0170.06719.11
5.4.370.0070.07719.13
5.4.360.0030.09019.15
5.4.350.0130.06719.18
5.4.340.0070.08019.05
5.4.320.0070.08019.09
5.4.310.0070.06019.16
5.4.300.0070.08019.02
5.4.290.0070.08319.18
5.4.280.0030.08319.04
5.4.270.0070.06719.03
5.4.260.0000.05019.04
5.4.250.0100.07319.02
5.4.240.0030.07718.94
5.4.230.0100.04718.95
5.4.220.0070.04319.16
5.4.210.0000.08019.22
5.4.200.0130.06718.87
5.4.190.0070.07718.86
5.4.180.0100.07318.89
5.4.170.0130.07019.11
5.4.160.0100.04019.16
5.4.150.0170.03719.07
5.4.140.0070.04016.51
5.4.130.0070.07016.48
5.4.120.0030.06716.51
5.4.110.0070.07716.47
5.4.100.0030.04316.44
5.4.90.0170.06016.45
5.4.80.0100.06316.50
5.4.70.0030.04716.59
5.4.60.0070.05316.46
5.4.50.0000.08316.40
5.4.40.0070.07316.49
5.4.30.0030.04316.25
5.4.20.0030.06716.39
5.4.10.0070.06316.30
5.4.00.0000.05715.87
5.3.290.0100.07014.63
5.3.280.0030.04014.71
5.3.270.0100.07314.57
5.3.260.0070.05014.67
5.3.250.0130.07014.61
5.3.240.0130.07314.65
5.3.230.0100.06314.73
5.3.220.0200.05314.61
5.3.210.0000.07314.72
5.3.200.0100.07314.67
5.3.190.0070.06314.51
5.3.180.0030.04314.68
5.3.170.0070.07714.55
5.3.160.0070.07014.64
5.3.150.0070.04714.51
5.3.140.0100.06714.68
5.3.130.0030.08014.66
5.3.120.0070.07714.65
5.3.110.0000.07714.51
5.3.100.0100.06014.04
5.3.90.0070.05014.01
5.3.80.0130.06714.09
5.3.70.0000.08314.15
5.3.60.0070.07314.02
5.3.50.0100.07013.95
5.3.40.0100.03314.05
5.3.30.0130.06713.98
5.3.20.0070.08013.68
5.3.10.0070.04313.72
5.3.00.0070.06013.79
5.2.170.0130.05711.73
5.2.160.0100.05311.73
5.2.150.0130.05311.73
5.2.140.0070.05311.73
5.2.130.0070.04011.73
5.2.120.0100.05311.73
5.2.110.0100.05711.73
5.2.100.0100.06011.73
5.2.90.0030.06311.73
5.2.80.0070.06711.73
5.2.70.0030.06711.73
5.2.60.0100.05711.73
5.2.50.0070.05011.73
5.2.40.0030.06311.73
5.2.30.0100.02711.73
5.2.20.0030.06011.73
5.2.10.0000.03711.73
5.2.00.0070.05311.73
5.1.60.0130.04311.73
5.1.50.0030.03711.73
5.1.40.0100.02311.73
5.1.30.0100.03011.73
5.1.20.0030.05711.73
5.1.10.0100.05311.73
5.1.00.0070.03011.73
5.0.50.0130.02011.73
5.0.40.0000.03711.73
5.0.30.0030.05011.73
5.0.20.0070.04011.73
5.0.10.0030.03311.73
5.0.00.0030.05711.73
4.4.90.0000.04011.73
4.4.80.0000.03311.73
4.4.70.0070.02711.73
4.4.60.0000.03011.73
4.4.50.0000.03311.73
4.4.40.0000.03011.73
4.4.30.0030.01711.73
4.4.20.0070.03011.73
4.4.10.0030.02011.73
4.4.00.0000.04311.73
4.3.110.0000.03711.73
4.3.100.0070.03011.73
4.3.90.0070.00711.73
4.3.80.0030.02011.73
4.3.70.0000.03711.73
4.3.60.0030.03011.73
4.3.50.0070.01011.73
4.3.40.0030.04711.73
4.3.30.0030.03311.73
4.3.20.0070.03011.73
4.3.10.0000.02311.73
4.3.00.0000.03311.73

preferences:
46.86 ms | 400 KiB | 5 Q