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 ''; } } 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.0100.00718.55
8.3.50.0120.00721.21
8.3.40.0140.00718.92
8.3.30.0030.01019.17
8.3.20.0030.00620.33
8.3.10.0050.00323.69
8.3.00.0080.00019.38
8.2.180.0070.00718.54
8.2.170.0070.00722.96
8.2.160.0070.00720.52
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0080.00026.16
8.2.120.0040.00422.21
8.2.110.0080.00322.20
8.2.100.0090.00317.75
8.2.90.0060.00319.17
8.2.80.0040.00417.97
8.2.70.0060.00317.63
8.2.60.0000.00817.93
8.2.50.0050.00318.07
8.2.40.0090.00020.01
8.2.30.0050.00218.04
8.2.20.0000.00717.80
8.2.10.0050.00218.09
8.2.00.0050.00317.84
8.1.280.0170.00325.92
8.1.270.0040.00423.98
8.1.260.0000.00726.35
8.1.250.0030.00528.09
8.1.240.0000.01023.88
8.1.230.0070.00419.16
8.1.220.0040.00417.74
8.1.210.0030.00618.77
8.1.200.0040.00917.25
8.1.190.0050.00317.22
8.1.180.0000.00918.10
8.1.170.0040.00420.10
8.1.160.0040.00422.00
8.1.150.0070.00018.92
8.1.140.0040.00417.52
8.1.130.0000.00717.87
8.1.120.0030.00517.45
8.1.110.0000.00817.54
8.1.100.0040.00417.51
8.1.90.0000.00717.44
8.1.80.0000.00717.55
8.1.70.0030.00317.51
8.1.60.0060.00717.60
8.1.50.0030.00617.61
8.1.40.0040.00417.50
8.1.30.0080.00017.68
8.1.20.0000.00717.52
8.1.10.0030.00517.63
8.1.00.0050.00317.57
8.0.300.0020.00518.77
8.0.290.0070.00016.88
8.0.280.0070.00018.39
8.0.270.0030.00317.19
8.0.260.0030.00318.49
8.0.250.0030.00317.09
8.0.240.0070.00017.05
8.0.230.0030.00316.98
8.0.220.0040.00416.88
8.0.210.0000.00716.98
8.0.200.0040.00417.12
8.0.190.0000.00816.95
8.0.180.0040.00416.92
8.0.170.0040.00417.06
8.0.160.0080.00017.07
8.0.150.0030.00316.92
8.0.140.0040.00416.97
8.0.130.0000.00613.46
8.0.120.0050.00316.89
8.0.110.0040.00417.02
8.0.100.0040.00416.91
8.0.90.0000.00716.88
8.0.80.0030.01316.94
8.0.70.0040.00416.98
8.0.60.0070.00017.03
8.0.50.0050.00317.06
8.0.30.0150.00517.10
8.0.20.0090.01317.40
8.0.10.0040.00416.93
8.0.00.0090.00916.92
7.4.330.0000.00715.02
7.4.320.0060.00016.53
7.4.300.0030.00316.63
7.4.290.0000.00816.69
7.4.280.0000.00816.59
7.4.270.0030.00316.60
7.4.260.0000.00716.67
7.4.250.0080.00016.58
7.4.240.0040.00316.55
7.4.230.0000.00716.62
7.4.220.0100.00716.46
7.4.210.0000.01416.72
7.4.200.0000.00716.43
7.4.160.0100.00716.63
7.4.150.0150.00917.40
7.4.140.0150.00317.86
7.4.130.0130.00716.57
7.4.120.0100.01116.61
7.4.110.0150.00616.55
7.4.100.0070.01016.74
7.4.90.0110.00616.68
7.4.80.0120.00619.39
7.4.70.0110.01016.57
7.4.60.0130.00316.45
7.4.50.0040.00416.62
7.4.40.0080.00816.45
7.4.30.0080.01116.48
7.4.00.0070.00715.18
7.3.330.0000.00513.38
7.3.320.0000.00513.32
7.3.310.0070.00016.47
7.3.300.0000.00716.41
7.3.290.0080.00716.43
7.3.280.0060.00916.40
7.3.270.0080.01717.40
7.3.260.0130.00616.53
7.3.250.0100.01116.40
7.3.240.0100.01116.51
7.3.230.0100.00716.49
7.3.210.0090.00916.45
7.3.200.0060.00919.39
7.3.190.0150.00616.46
7.3.180.0000.01516.67
7.3.170.0030.01316.59
7.3.160.0110.01016.40
7.2.330.0130.00916.64
7.2.320.0070.01016.43
7.2.310.0030.01416.51
7.2.300.0070.01016.79
7.2.290.0080.01616.71
7.1.70.0000.00816.92
7.1.60.0100.01419.32
7.1.50.0170.01034.91
7.1.00.0070.07322.31
7.0.200.0590.00315.06
7.0.140.0070.07021.93
7.0.60.0070.08319.81
7.0.50.0130.07717.73
7.0.40.0030.04320.27
7.0.30.0570.07020.08
7.0.20.0330.07020.07
7.0.10.0170.08020.25
7.0.00.0030.05320.08
5.6.210.0030.04020.77
5.6.200.0070.04318.16
5.6.190.0070.04320.33
5.6.180.0300.03720.61
5.6.170.0270.05320.58
5.6.160.0000.04320.44
5.6.150.0030.05318.18
5.6.140.0130.07318.25
5.6.130.0030.08018.18
5.6.120.0070.06321.00
5.6.110.0070.05321.14
5.6.100.0130.06721.03
5.6.90.0070.05320.98
5.6.80.0000.08320.34
5.5.350.0300.06720.42
5.5.340.0100.05317.95
5.5.330.0030.04320.19
5.5.320.0330.07320.30
5.5.310.0400.08020.20
5.5.300.0030.08318.08
5.5.290.0100.04718.08
5.5.280.0030.09320.78
5.5.270.0070.08320.85
5.5.260.0100.08320.85
5.5.250.0000.07720.70
5.5.240.2800.04320.36
5.4.450.0870.05719.56
5.4.440.0630.06319.63
5.4.430.0470.06319.47
5.4.420.0870.05719.56
5.4.410.0670.05019.47
5.4.400.0670.06319.16
5.4.390.0630.05719.26
5.4.380.0370.05319.03
5.4.370.0700.07319.15
5.4.360.0400.04719.23
5.4.350.0770.05319.00
5.4.340.0080.04512.02
5.4.320.0070.03912.50
5.4.310.0060.04112.51
5.4.300.0060.04612.52
5.4.290.0060.03812.51
5.4.280.0100.03012.40
5.4.270.0010.04112.41
5.4.260.0070.03912.41
5.4.250.0060.03712.41
5.4.240.0070.04612.41
5.4.230.0090.03512.39
5.4.220.0030.04512.40
5.4.210.0070.03812.40
5.4.200.0030.04112.39
5.4.190.0060.04312.40
5.4.180.0050.04212.39
5.4.170.0080.03412.41
5.4.160.0060.03912.40
5.4.150.0060.04412.40
5.4.140.0090.03812.08
5.4.130.0080.04112.07
5.4.120.0050.03712.03
5.4.110.0100.03312.03
5.4.100.0060.03512.02
5.4.90.0040.04112.02
5.4.80.0020.04012.02
5.4.70.0070.03812.02
5.4.60.0050.04112.02
5.4.50.0090.04412.02
5.4.40.0080.03712.01
5.4.30.0050.03612.00
5.4.20.0070.03512.01
5.4.10.0050.03512.00
5.4.00.0040.03811.49
5.3.290.0060.03912.80
5.3.280.0050.03912.71
5.3.270.0080.04212.72
5.3.260.0100.04012.72
5.3.250.0030.04012.72
5.3.240.0050.04012.72
5.3.230.0070.03612.70
5.3.220.0090.03812.68
5.3.210.0130.03612.68
5.3.200.0090.04712.68
5.3.190.0030.04112.68
5.3.180.0060.04212.67
5.3.170.0050.04312.67
5.3.160.0080.03812.68
5.3.150.0060.03812.68
5.3.140.0080.03612.66
5.3.130.0070.04412.66
5.3.120.0070.04312.66
5.3.110.0080.03712.66
5.3.100.0040.03912.13
5.3.90.0080.04412.11
5.3.80.0070.04312.10
5.3.70.0060.04512.10
5.3.60.0060.04212.09
5.3.50.0060.04412.04
5.3.40.0070.03812.04
5.3.30.0060.04512.01
5.3.20.0070.03811.77
5.3.10.0040.03811.74
5.3.00.0060.04011.73
5.2.170.0040.0329.24
5.2.160.0070.0339.23
5.2.150.0030.0339.23
5.2.140.0030.0329.23
5.2.130.0060.0409.20
5.2.120.0070.0339.20
5.2.110.0010.0349.19
5.2.100.0070.0329.19
5.2.90.0050.0339.19
5.2.80.0030.0329.19
5.2.70.0050.0309.19
5.2.60.0040.0309.14
5.2.50.0060.0339.11
5.2.40.0030.0339.09
5.2.30.0030.0349.06
5.2.20.0090.0259.05
5.2.10.0100.0238.95
5.2.00.0070.0328.82
5.1.60.0050.0238.10
5.1.50.0060.0258.10
5.1.40.0050.0288.08
5.1.30.0040.0268.43
5.1.20.0050.0268.45
5.1.10.0020.0288.18
5.1.00.0060.0318.18
5.0.50.0080.0236.65
5.0.40.0040.0206.51
5.0.30.0020.0336.33
5.0.20.0020.0246.29
5.0.10.0030.0216.27
5.0.00.0040.0306.26
4.4.90.0020.0164.78
4.4.80.0030.0144.75
4.4.70.0040.0244.75
4.4.60.0040.0214.75
4.4.50.0050.0184.77
4.4.40.0050.0264.71
4.4.30.0040.0164.76
4.4.20.0040.0234.85
4.4.10.0000.0204.85
4.4.00.0010.0284.76
4.3.110.0030.0184.67
4.3.100.0050.0154.67
4.3.90.0030.0144.64
4.3.80.0030.0244.58
4.3.70.0030.0154.63
4.3.60.0050.0144.63
4.3.50.0030.0154.63
4.3.40.0040.0244.54
4.3.30.0020.0173.30
4.3.20.0020.0203.28
4.3.10.0010.0213.24
4.3.00.0100.0306.99

preferences:
42.72 ms | 401 KiB | 5 Q