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

Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C7Yli
function name:  (null)
number of ops:  20
compiled vars:  !0 = $sum
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   NEW                                              $1      'demo'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   30     3        INIT_METHOD_CALL                                         !0, 'digit_sum'
          4        SEND_VAL_EX                                              'sfsdfsdfds'
          5        DO_FCALL                                      0  $4      
          6        ECHO                                                     $4
   31     7        INIT_METHOD_CALL                                         !0, 'digit_sum'
          8        SEND_VAL_EX                                              12345
          9        DO_FCALL                                      0  $5      
         10        ECHO                                                     $5
   33    11        INIT_METHOD_CALL                                         !0, 'digit_sum'
         12        SEND_VAL_EX                                              3253435674
         13        DO_FCALL                                      0  $6      
         14        ECHO                                                     $6
   35    15        INIT_METHOD_CALL                                         !0, 'digit_sum'
         16        SEND_VAL_EX                                              32
         17        DO_FCALL                                      0  $7      
         18        ECHO                                                     $7
         19      > RETURN                                                   1

Class demo:
Function digit_sum:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 15
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 15
Branch analysis from position: 31
Branch analysis from position: 15
Found catch point at position: 39
Branch analysis from position: 39
2 jumps found. (Code = 107) Position 1 = 40, Position 2 = -2
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C7Yli
function name:  digit_sum
number of ops:  44
compiled vars:  !0 = $digit, !1 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
   10     1        GET_TYPE                                         ~2      !0
          2        IS_EQUAL                                                 ~2, 'string'
          3      > JMPZ                                                     ~3, ->10
   11     4    >   NEW                                              $4      'Exception'
          5        CONCAT                                           ~5      !0, '+is+not+a+valid+number+%3Cbr%2F%3E'
          6        SEND_VAL_EX                                              ~5
          7        DO_FCALL                                      0          
          8      > THROW                                         0          $4
   10     9*       JMP                                                      ->38
   13    10    >   ASSIGN_OBJ                                               'num'
         11        OP_DATA                                                  !0
   14    12        ASSIGN_OBJ                                               'sum'
         13        OP_DATA                                                  0
   15    14      > JMP                                                      ->28
   16    15    >   FETCH_OBJ_R                                      ~10     'num'
         16        MOD                                              ~11     ~10, 10
         17        ASSIGN_OBJ                                               'rem'
         18        OP_DATA                                                  ~11
   17    19        FETCH_OBJ_R                                      ~13     'sum'
         20        FETCH_OBJ_R                                      ~14     'rem'
         21        ADD                                              ~15     ~13, ~14
         22        ASSIGN_OBJ                                               'sum'
         23        OP_DATA                                                  ~15
   18    24        FETCH_OBJ_R                                      ~17     'num'
         25        DIV                                              ~18     ~17, 10
         26        ASSIGN_OBJ                                               'num'
         27        OP_DATA                                                  ~18
   15    28    >   FETCH_OBJ_R                                      ~19     'num'
         29        IS_SMALLER                                               0, ~19
         30      > JMPNZ                                                    ~20, ->15
   20    31    >   ROPE_INIT                                     3  ~22     'Sum+of+no++'
         32        ROPE_ADD                                      1  ~22     ~22, !0
         33        ROPE_END                                      2  ~21     ~22, '+is+%3D+'
         34        FETCH_OBJ_R                                      ~24     'sum'
         35        CONCAT                                           ~25     ~21, ~24
         36        CONCAT                                           ~26     ~25, '%3Cbr%2F%3E'
         37      > RETURN                                                   ~26
         38*       JMP                                                      ->43
   22    39  E > > CATCH                                       last         'Exception'
   23    40    >   INIT_METHOD_CALL                                         !1, 'getMessage'
         41        DO_FCALL                                      0  $27     
         42        ECHO                                                     $27
   25    43      > RETURN                                                   null

End of function digit_sum

End of class demo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.51 ms | 1004 KiB | 13 Q