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"; // 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/hiHZN
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   INIT_FCALL                                               'set_exception_handler'
          1        SEND_VAL                                                 'exceptionHandler'
          2        DO_ICALL                                                 
   48     3        INIT_FCALL_BY_NAME                                       'a'
          4        SEND_VAL_EX                                              '1'
          5        DO_FCALL                                      0          
   53     6      > RETURN                                                   1

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

End of function a

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.11 ms | 1404 KiB | 21 Q