3v4l.org

run code in 300+ PHP versions simultaneously
<?php $errorTypes = [ E_ERROR => 'Error', E_WARNING => 'Warning', E_PARSE => 'Parse Error', E_NOTICE => 'Notice', E_CORE_ERROR => 'Core Error', E_CORE_WARNING => 'Core Warning', E_COMPILE_ERROR => 'Compile Error', E_COMPILE_WARNING => 'Compile Warning', E_USER_ERROR => 'User Error', E_USER_WARNING => 'User Warning', E_USER_NOTICE => 'User Notice', E_USER_DEPRECATED => 'Deprecated', E_STRICT => 'Strict Standards', E_RECOVERABLE_ERROR => 'Catchable Fatal' ]; $fatalErrorTypes = [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR]; function log_error($num, $str, $file, $line, $context = null, $exit = true) { global $errorTypes; global $fatalErrorTypes; $bFatal = true; if (isset($errorTypes[$num])) { $errType = $errorTypes[$num]; $bFatal = in_array($num, $fatalErrorTypes); } else { $errType = "Unknown error #$num"; } // would normally record stuff here echo "PHP $errType [$file:$line]: $str\n"; if ($bFatal && $exit) { die; } } function check_for_fatal() { global $fatalErrorTypes; $error = error_get_last(); if (in_array($error['type'], $fatalErrorTypes)) { log_error($error["type"], $error["message"], $error["file"], $error["line"], null, false); $output = '{"errors":[{"code":"internal_server_error"}]}'; // would normally record stuff here echo $output; } } function log_exception(\Exception $e) { echo get_class($e) . ': ' . $e->getMessage(); } register_shutdown_function('check_for_fatal'); set_error_handler('log_error'); set_exception_handler('log_exception'); try { $broken = null; echo $broken->length(); } catch (\Exception $e) { log_exception($e); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 16
Branch analysis from position: 16
2 jumps found. (Code = 107) Position 1 = 17, Position 2 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/q0kfh
function name:  (null)
number of ops:  21
compiled vars:  !0 = $errorTypes, !1 = $fatalErrorTypes, !2 = $broken, !3 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   19     1        ASSIGN                                                   !1, <array>
   60     2        INIT_FCALL                                               'register_shutdown_function'
          3        SEND_VAL                                                 'check_for_fatal'
          4        DO_ICALL                                                 
   61     5        INIT_FCALL                                               'set_error_handler'
          6        SEND_VAL                                                 'log_error'
          7        DO_ICALL                                                 
   62     8        INIT_FCALL                                               'set_exception_handler'
          9        SEND_VAL                                                 'log_exception'
         10        DO_ICALL                                                 
   65    11        ASSIGN                                                   !2, null
   66    12        INIT_METHOD_CALL                                         !2, 'length'
         13        DO_FCALL                                      0  $10     
         14        ECHO                                                     $10
         15      > JMP                                                      ->20
   67    16  E > > CATCH                                       last         'Exception'
   68    17    >   INIT_FCALL                                               'log_exception'
         18        SEND_VAR                                                 !3
         19        DO_FCALL                                      0          
   69    20    > > RETURN                                                   1

Function log_error:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 19
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 46) Position 1 = 33, Position 2 = 34
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 36
Branch analysis from position: 35
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
Branch analysis from position: 19
2 jumps found. (Code = 46) Position 1 = 33, Position 2 = 34
Branch analysis from position: 33
Branch analysis from position: 34
filename:       /in/q0kfh
function name:  log_error
number of ops:  37
compiled vars:  !0 = $num, !1 = $str, !2 = $file, !3 = $line, !4 = $context, !5 = $exit, !6 = $errorTypes, !7 = $fatalErrorTypes, !8 = $bFatal, !9 = $errType
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
          4        RECV_INIT                                        !4      null
          5        RECV_INIT                                        !5      <true>
   23     6        BIND_GLOBAL                                              !6, 'errorTypes'
   24     7        BIND_GLOBAL                                              !7, 'fatalErrorTypes'
   26     8        ASSIGN                                                   !8, <true>
   28     9        ISSET_ISEMPTY_DIM_OBJ                         0          !6, !0
         10      > JMPZ                                                     ~11, ->19
   29    11    >   FETCH_DIM_R                                      ~12     !6, !0
         12        ASSIGN                                                   !9, ~12
   30    13        INIT_FCALL                                               'in_array'
         14        SEND_VAR                                                 !0
         15        SEND_VAR                                                 !7
         16        DO_ICALL                                         $14     
         17        ASSIGN                                                   !8, $14
         18      > JMP                                                      ->22
   32    19    >   NOP                                                      
         20        FAST_CONCAT                                      ~16     'Unknown+error+%23', !0
         21        ASSIGN                                                   !9, ~16
   36    22    >   ROPE_INIT                                     9  ~19     'PHP+'
         23        ROPE_ADD                                      1  ~19     ~19, !9
         24        ROPE_ADD                                      2  ~19     ~19, '+%5B'
         25        ROPE_ADD                                      3  ~19     ~19, !2
         26        ROPE_ADD                                      4  ~19     ~19, '%3A'
         27        ROPE_ADD                                      5  ~19     ~19, !3
         28        ROPE_ADD                                      6  ~19     ~19, '%5D%3A+'
         29        ROPE_ADD                                      7  ~19     ~19, !1
         30        ROPE_END                                      8  ~18     ~19, '%0A'
         31        ECHO                                                     ~18
   38    32      > JMPZ_EX                                          ~24     !8, ->34
         33    >   BOOL                                             ~24     !5
         34    > > JMPZ                                                     ~24, ->36
   39    35    > > EXIT                                                     
   41    36    > > RETURN                                                   null

End of function log_error

Function check_for_fatal:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 24
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/q0kfh
function name:  check_for_fatal
number of ops:  25
compiled vars:  !0 = $fatalErrorTypes, !1 = $error, !2 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   BIND_GLOBAL                                              !0, 'fatalErrorTypes'
   46     1        INIT_FCALL                                               'error_get_last'
          2        DO_ICALL                                         $3      
          3        ASSIGN                                                   !1, $3
   47     4        INIT_FCALL                                               'in_array'
          5        FETCH_DIM_R                                      ~5      !1, 'type'
          6        SEND_VAL                                                 ~5
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $6      
          9      > JMPZ                                                     $6, ->24
   48    10    >   INIT_FCALL                                               'log_error'
         11        FETCH_DIM_R                                      ~7      !1, 'type'
         12        SEND_VAL                                                 ~7
         13        FETCH_DIM_R                                      ~8      !1, 'message'
         14        SEND_VAL                                                 ~8
         15        FETCH_DIM_R                                      ~9      !1, 'file'
         16        SEND_VAL                                                 ~9
         17        FETCH_DIM_R                                      ~10     !1, 'line'
         18        SEND_VAL                                                 ~10
         19        SEND_VAL                                                 null
         20        SEND_VAL                                                 <false>
         21        DO_FCALL                                      0          
   50    22        ASSIGN                                                   !2, '%7B%22errors%22%3A%5B%7B%22code%22%3A%22internal_server_error%22%7D%5D%7D'
   52    23        ECHO                                                     !2
   54    24    > > RETURN                                                   null

End of function check_for_fatal

Function log_exception:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/q0kfh
function name:  log_exception
number of ops:  8
compiled vars:  !0 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   RECV                                             !0      
   57     1        GET_CLASS                                        ~1      !0
          2        CONCAT                                           ~2      ~1, '%3A+'
          3        INIT_METHOD_CALL                                         !0, 'getMessage'
          4        DO_FCALL                                      0  $3      
          5        CONCAT                                           ~4      ~2, $3
          6        ECHO                                                     ~4
   58     7      > RETURN                                                   null

End of function log_exception

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
179.34 ms | 1407 KiB | 25 Q