3v4l.org

run code in 300+ PHP versions simultaneously
<?php class demo { private $sum; private $num; private $rem; public function digit_sum($digit) { //echo gettype($digit).'<br>'; try { if (gettype($digit) == 'string') { throw new Exception($digit . ' is not a valid number <br/>'); } else { $this->num = $digit; $this->sum = 0; while ($this->num > 0) { $this->rem = $this->num % 10; $this->sum = $this->sum + $this->rem; $this->num = $this->num / 10; } return "Sum of no $digit is = " . $this->sum . '<br/>'; } } catch (Exception $e) { echo $e->getMessage(); } } } $sum = new demo(); echo $sum->digit_sum('sfsdfsdfds'); echo $sum->digit_sum(12345); // outputs correct sum echo $sum->digit_sum(3253435674); echo $sum->digit_sum(32);

Abusive script

This script was stopped while abusing our resources

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.110.0060.00920.94
8.3.100.0130.00324.06
8.3.90.0240.02026.77
8.3.80.0040.00716.75
8.3.70.0090.00916.63
8.3.60.0270.01316.88
8.3.50.0150.01621.27
8.3.40.0100.00718.89
8.3.30.0090.00618.71
8.3.20.0030.00620.34
8.3.10.0040.00720.66
8.3.00.0070.01423.50
8.2.230.0130.00022.58
8.2.220.0050.01437.54
8.2.210.0040.00426.77
8.2.200.0030.00716.50
8.2.190.0000.01816.75
8.2.180.0140.00725.92
8.2.170.0200.00322.96
8.2.160.0280.02819.36
8.2.150.0260.01024.18
8.2.140.0050.00524.66
8.2.130.0080.00026.16
8.2.120.0050.00320.75
8.2.110.0090.00320.99
8.2.100.0140.01017.91
8.2.90.0050.00517.75
8.2.80.0030.00617.97
8.2.70.0030.00617.75
8.2.60.0030.00617.75
8.2.50.0000.00817.80
8.2.40.0030.00619.66
8.2.30.0060.00319.36
8.2.20.0040.00418.05
8.2.10.0060.00318.14
8.2.00.0000.00817.76
8.1.290.0030.00618.88
8.1.280.0130.00725.92
8.1.270.0000.01523.83
8.1.260.0080.00026.35
8.1.250.0070.00728.09
8.1.240.0070.00723.64
8.1.230.0040.00820.88
8.1.220.0050.00317.78
8.1.210.0100.00518.79
8.1.200.0000.01017.48
8.1.190.0000.01017.35
8.1.180.0060.00318.10
8.1.170.0030.00617.62
8.1.160.0040.00422.14
8.1.150.0080.00019.02
8.1.140.0070.00019.66
8.1.130.0050.00217.75
8.1.120.0040.00417.48
8.1.110.0060.00317.49
8.1.100.0000.00717.44
8.1.90.0000.00817.45
8.1.80.0000.00817.49
8.1.70.0040.00417.49
8.1.60.0070.00717.51
8.1.50.0080.00417.54
8.1.40.0040.00417.58
8.1.30.0030.00617.71
8.1.20.0000.00917.71
8.1.10.0120.00317.52
8.1.00.0080.00817.57
8.0.300.0040.00419.98
8.0.290.0040.00416.75
8.0.280.0000.00818.50
8.0.270.0050.00217.33
8.0.260.0060.00017.41
8.0.250.0070.00017.02
8.0.240.0100.00017.06
8.0.230.0000.00717.07
8.0.220.0040.00416.85
8.0.210.0070.00016.94
8.0.200.0050.00317.06
8.0.190.0000.00716.89
8.0.180.0050.00217.00
8.0.170.0000.00816.99
8.0.160.0040.00417.05
8.0.150.0000.00716.88
8.0.140.0030.00316.93
8.0.130.0030.00313.42
8.0.120.0000.00916.90
8.0.110.0050.00316.92
8.0.100.0050.00316.91
8.0.90.0050.00316.92
8.0.80.0060.00916.92
8.0.70.0030.00716.82
8.0.60.0040.00416.94
8.0.50.0030.00616.97
8.0.30.0090.01117.28
8.0.20.0090.01017.40
8.0.10.0070.00016.96
8.0.00.0150.00616.79
7.4.330.0000.00515.09
7.4.320.0030.00616.50
7.4.300.0030.00416.58
7.4.290.0030.00516.41
7.4.280.0050.00516.66
7.4.270.0030.00316.64
7.4.260.0030.00516.59
7.4.250.0040.00416.56
7.4.240.0030.00416.59
7.4.230.0030.00316.52
7.4.220.0110.00616.43
7.4.210.0040.01116.65
7.4.200.0050.00316.52
7.4.160.0120.00816.44
7.4.150.0110.00717.40
7.4.140.0130.00717.86
7.4.130.0150.00316.59
7.4.120.0090.00816.54
7.4.110.0070.01116.36
7.4.100.0070.01016.52
7.4.90.0110.00816.51
7.4.80.0060.01419.39
7.4.70.0050.00716.64
7.4.60.0030.01416.64
7.4.50.0000.01516.44
7.4.40.0120.00416.45
7.4.30.0060.01516.49
7.4.00.0030.01315.13
7.3.330.0000.00613.44
7.3.320.0030.00313.20
7.3.310.0000.00716.28
7.3.300.0050.00216.44
7.3.290.0050.00916.44
7.3.280.0060.01216.41
7.3.270.0030.01317.40
7.3.260.0110.01016.66
7.3.250.0100.01016.38
7.3.240.0090.00716.59
7.3.230.0100.00716.52
7.3.210.0130.00416.47
7.3.200.0060.01616.53
7.3.190.0120.00616.61
7.3.180.0110.00616.61
7.3.170.0150.00616.61
7.3.160.0120.00416.40
7.2.330.0090.00916.82
7.2.320.0070.01716.86
7.2.310.0090.00916.63
7.2.300.0110.00716.80
7.2.290.0050.01016.72
7.2.60.0200.01016.62
7.1.200.0000.00815.76
7.1.70.0030.00517.27
7.1.60.0080.00316.95
7.1.00.0000.08022.33
7.0.200.0300.00414.70
7.0.110.0570.07320.30
7.0.100.0470.07720.27
7.0.90.0270.07020.33
7.0.80.0370.07020.29
7.0.70.0400.06020.32
7.0.60.0470.07320.30
7.0.50.0330.06020.22
7.0.40.0430.07020.42
7.0.30.0330.05320.32
7.0.20.0430.06720.32
7.0.10.0430.04320.32
7.0.00.0300.05720.28
5.6.260.0100.05321.06
5.6.250.0100.07721.13
5.6.240.0130.06021.06
5.6.230.0270.05320.97
5.6.220.0170.06020.96
5.6.210.0100.09020.95
5.6.200.0130.06020.93
5.6.190.0200.05021.09
5.6.180.0070.08320.94
5.6.170.0370.05321.02
5.6.160.0070.06021.07
5.6.150.0070.06020.95
5.6.140.0130.05320.84
5.6.130.0130.05020.93
5.6.120.0100.05721.09
5.6.110.0100.06020.83
5.6.100.0230.04720.82
5.6.90.0170.07321.03
5.6.80.0030.06320.39
5.6.70.0230.06020.23
5.6.60.0170.04720.41
5.6.50.0230.04020.24
5.6.40.0100.06320.39
5.6.30.0100.05720.12
5.6.20.0130.05320.40
5.6.10.0070.07320.20
5.6.00.0070.05720.09

preferences:
117.34 ms | 403 KiB | 5 Q