3v4l.org

run code in 300+ PHP versions simultaneously
<?php function exceptionHandler($exception) { // these are our templates $traceline = "#%s %s(%s): %s(%s)"; $msg = "PHP Exception `%s`: %s\nStack trace:\n%s\n thrown in %s on line %s"; $msg = "PHP Fatal error: Uncaught exception '%s' with message '%s' in %s:%s\nStack trace:\n%s\n thrown in %s on line %s"; // alter your trace as you please, here $trace = $exception->getTrace(); foreach ($trace as $key => $stackPoint) { // I'm converting arguments to their type // (prevents passwords from ever getting logged as anything other than 'string') $trace[$key]['args'] = array_map('gettype', $trace[$key]['args']); } // build your tracelines $result = array(); foreach ($trace as $key => $stackPoint) { $result[] = sprintf( $traceline, $key, $stackPoint['file'], $stackPoint['line'], $stackPoint['function'], implode(', ', $stackPoint['args']) ); } // trace always ends with {main} $result[] = '#' . ++$key . ' {main}'; // write tracelines into main template $msg = sprintf( $msg, get_class($exception), $exception->getMessage(), implode("\n", $result), $exception->getFile(), $exception->getLine() ); // log or echo as you please print $msg; } set_exception_handler("exceptionHandler"); a("1"); function a($i) { throw new Exception("Just invoking the exception handler"); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9kKG0
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   INIT_FCALL                                               'set_exception_handler'
          1        SEND_VAL                                                 'exceptionHandler'
          2        DO_ICALL                                                 
   49     3        INIT_FCALL_BY_NAME                                       'a'
          4        SEND_VAL_EX                                              '1'
          5        DO_FCALL                                      0          
   54     6      > RETURN                                                   1

Function exceptionhandler:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 20
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 20
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 44
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 44
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
Branch analysis from position: 20
filename:       /in/9kKG0
function name:  exceptionHandler
number of ops:  72
compiled vars:  !0 = $exception, !1 = $traceline, !2 = $msg, !3 = $trace, !4 = $stackPoint, !5 = $key, !6 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    6     1        ASSIGN                                                   !1, '%23%25s+%25s%28%25s%29%3A+%25s%28%25s%29'
    7     2        ASSIGN                                                   !2, 'PHP+Exception+%60%25s%60%3A+%25s%0AStack+trace%3A%0A%25s%0A++thrown+in+%25s+on+line+%25s'
    8     3        ASSIGN                                                   !2, 'PHP+Fatal+error%3A++Uncaught+exception+%27%25s%27+with+message+%27%25s%27+in+%25s%3A%25s%0AStack+trace%3A%0A%25s%0A++thrown+in+%25s+on+line+%25s'
   11     4        INIT_METHOD_CALL                                         !0, 'getTrace'
          5        DO_FCALL                                      0  $10     
          6        ASSIGN                                                   !3, $10
   12     7      > FE_RESET_R                                       $12     !3, ->20
          8    > > FE_FETCH_R                                       ~13     $12, !4, ->20
          9    >   ASSIGN                                                   !5, ~13
   15    10        INIT_FCALL                                               'array_map'
         11        SEND_VAL                                                 'gettype'
         12        FETCH_DIM_R                                      ~17     !3, !5
         13        FETCH_DIM_R                                      ~18     ~17, 'args'
         14        SEND_VAL                                                 ~18
         15        DO_ICALL                                         $19     
         16        FETCH_DIM_W                                      $15     !3, !5
         17        ASSIGN_DIM                                               $15, 'args'
         18        OP_DATA                                                  $19
   12    19      > JMP                                                      ->8
         20    >   FE_FREE                                                  $12
   19    21        ASSIGN                                                   !6, <array>
   20    22      > FE_RESET_R                                       $21     !3, ->44
         23    > > FE_FETCH_R                                       ~22     $21, !4, ->44
         24    >   ASSIGN                                                   !5, ~22
   21    25        INIT_FCALL                                               'sprintf'
   22    26        SEND_VAR                                                 !1
   23    27        SEND_VAR                                                 !5
   24    28        FETCH_DIM_R                                      ~25     !4, 'file'
         29        SEND_VAL                                                 ~25
   25    30        FETCH_DIM_R                                      ~26     !4, 'line'
         31        SEND_VAL                                                 ~26
   26    32        FETCH_DIM_R                                      ~27     !4, 'function'
         33        SEND_VAL                                                 ~27
   27    34        INIT_FCALL                                               'implode'
         35        SEND_VAL                                                 '%2C+'
         36        FETCH_DIM_R                                      ~28     !4, 'args'
         37        SEND_VAL                                                 ~28
         38        DO_ICALL                                         $29     
         39        SEND_VAR                                                 $29
         40        DO_ICALL                                         $30     
   21    41        ASSIGN_DIM                                               !6
   27    42        OP_DATA                                                  $30
   20    43      > JMP                                                      ->23
         44    >   FE_FREE                                                  $21
   31    45        PRE_INC                                          ~32     !5
         46        CONCAT                                           ~33     '%23', ~32
         47        CONCAT                                           ~34     ~33, '+%7Bmain%7D'
         48        ASSIGN_DIM                                               !6
         49        OP_DATA                                                  ~34
   34    50        INIT_FCALL                                               'sprintf'
   35    51        SEND_VAR                                                 !2
   36    52        GET_CLASS                                        ~35     !0
         53        SEND_VAL                                                 ~35
   37    54        INIT_METHOD_CALL                                         !0, 'getMessage'
         55        DO_FCALL                                      0  $36     
         56        SEND_VAR                                                 $36
   38    57        INIT_FCALL                                               'implode'
         58        SEND_VAL                                                 '%0A'
         59        SEND_VAR                                                 !6
         60        DO_ICALL                                         $37     
         61        SEND_VAR                                                 $37
   39    62        INIT_METHOD_CALL                                         !0, 'getFile'
         63        DO_FCALL                                      0  $38     
         64        SEND_VAR                                                 $38
   40    65        INIT_METHOD_CALL                                         !0, 'getLine'
         66        DO_FCALL                                      0  $39     
         67        SEND_VAR                                                 $39
         68        DO_ICALL                                         $40     
   34    69        ASSIGN                                                   !2, $40
   44    70        ECHO                                                     !2
   45    71      > RETURN                                                   null

End of function exceptionhandler

Function a:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/9kKG0
function name:  a
number of ops:  6
compiled vars:  !0 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   RECV                                             !0      
   53     1        NEW                                              $1      'Exception'
          2        SEND_VAL_EX                                              'Just+invoking+the+exception+handler'
          3        DO_FCALL                                      0          
          4      > THROW                                         0          $1
   54     5*     > RETURN                                                   null

End of function a

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.87 ms | 1404 KiB | 21 Q