3v4l.org

run code in 300+ PHP versions simultaneously
<?php // 为避免污染全局命名空间,已对所有标识符加 `e` 前缀 /** * 运行模式 * * debug 调试模式, 会开启详细的日志记录和错误提示 * * default 默认模式, 会输出错误提示 * * production 生产模式, 不会执行任何额外操作, 最高效地执行代码 */ ob_start(); const eDebug = 2; const eDefault = 1; const eProduction = 0; const eRunMode = eDebug; // 默认关掉所有错误提示 error_reporting(0); // 如果是默认模式,打开致命错误和解析错误的报告 if(eRunMode >= eDefault) error_reporting(E_ERROR | E_PARSE); // 如果是调试模式,打开全部错误提示,并启用修改建议提示 if(eRunMode >= eDebug) error_reporting(E_ALL | E_STRICT); class ePHPException extends Exception { protected $severity; protected $varList; public function __construct($message = "", $code = 0, $severity = 1, $filename = __FILE__, $lineno = __LINE__, Exception $previous = null, $varList = []) { $this->severity = $severity; $this->file = $filename; $this->line = $lineno; $this->varList = $varList; // 调用父类的构造函数 parent::__construct($message, $code, $previous); } public function getSeverity() { return $this->severity; } public function getVarList() { return $this->varList; } } set_error_handler(function($no, $str, $file, $line, $varList) { throw new ePHPException($str, 0, $no, $file, $line, null, $varList); }); register_shutdown_function(function() { $error = error_get_last(); if($error['type'] === E_ERROR) throw new ePHPException($error['message'], 0, $error['type'], $error['file'], $error['line']); }); if(eRunMode <= eProduction) { set_exception_handler(function(Exception $exception) { header("Content-Type: text/plant; charset=UTF-8"); die(header("HTTP/1.1 500 Internal Server Error")); }); } else { echo "+++"; set_exception_handler(function(Exception $exception) { echo "---"; // 暂时我们只打算以纯文本的形式展示信息 header("Content-Type: text/plant; charset=UTF-8"); // 整体模版 $msg = "Exception `%s`: %s\nStack trace:\n%s\n thrown in %s on line %s"; // 栈的每一行的模版 $traceline = "#%s %s (%s): %s(%s)"; // 从异常对象获取运行栈 $trace = $exception->getTrace(); // 只有在调试模式才会显示参数的值,其他模式下只显示参数类型 if(eRunMode < eDebug) foreach ($trace as $key => $stackPoint) $trace[$key]['args'] = array_map('gettype', $trace[$key]['args']); $result = []; // 对运行栈的每一项应用模版 foreach ($trace as $key => $stackPoint) $result[] = sprintf( $traceline, $key, $stackPoint['file'], $stackPoint['line'], $stackPoint['function'], implode(', ', $stackPoint['args']) ); $result[] = '#' . ++$key . ' {main}'; // 应用整体模版 $msg = sprintf( $msg, get_class($exception), $exception->getMessage(), implode("\n", $result), $exception->getFile(), $exception->getLine() ); // 打印运行栈等信息 print $msg; // 如果当前是调试模式,且异常对象是我们构造的 ePHPException 类型,打印符号表 if(eRunMode >= eDebug && $exception instanceof ePHPException) print_r($exception->getVarList()); }); } array_keys(1);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 23
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 40
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
Branch analysis from position: 16
filename:       /in/s6b9G
function name:  (null)
number of ops:  49
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   INIT_FCALL                                               'ob_start'
          1        DO_ICALL                                                 
   14     2        DECLARE_CONST                                            'eDebug', 2
   15     3        DECLARE_CONST                                            'eDefault', 1
   16     4        DECLARE_CONST                                            'eProduction', 0
   18     5        DECLARE_CONST                                            'eRunMode', <const ast>
   21     6        INIT_FCALL                                               'error_reporting'
          7        SEND_VAL                                                 0
          8        DO_ICALL                                                 
   23     9        FETCH_CONSTANT                                   ~2      'eRunMode'
         10        FETCH_CONSTANT                                   ~3      'eDefault'
         11        IS_SMALLER_OR_EQUAL                                      ~3, ~2
         12      > JMPZ                                                     ~4, ->16
   24    13    >   INIT_FCALL                                               'error_reporting'
         14        SEND_VAL                                                 5
         15        DO_ICALL                                                 
   26    16    >   FETCH_CONSTANT                                   ~6      'eRunMode'
         17        FETCH_CONSTANT                                   ~7      'eDebug'
         18        IS_SMALLER_OR_EQUAL                                      ~7, ~6
         19      > JMPZ                                                     ~8, ->23
   27    20    >   INIT_FCALL                                               'error_reporting'
         21        SEND_VAL                                                 32767
         22        DO_ICALL                                                 
   56    23    >   INIT_FCALL                                               'set_error_handler'
         24        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fs6b9G%3A56%240'
   59    25        SEND_VAL                                                 ~10
         26        DO_ICALL                                                 
   61    27        INIT_FCALL                                               'register_shutdown_function'
         28        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fs6b9G%3A61%241'
   65    29        SEND_VAL                                                 ~12
         30        DO_ICALL                                                 
   67    31        FETCH_CONSTANT                                   ~14     'eRunMode'
         32        FETCH_CONSTANT                                   ~15     'eProduction'
         33        IS_SMALLER_OR_EQUAL                                      ~14, ~15
         34      > JMPZ                                                     ~16, ->40
   69    35    >   INIT_FCALL                                               'set_exception_handler'
         36        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fs6b9G%3A69%242'
   73    37        SEND_VAL                                                 ~17
         38        DO_ICALL                                                 
         39      > JMP                                                      ->45
   77    40    >   ECHO                                                     '%2B%2B%2B'
   78    41        INIT_FCALL                                               'set_exception_handler'
         42        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fs6b9G%3A78%243'
  127    43        SEND_VAL                                                 ~19
         44        DO_ICALL                                                 
  132    45    >   INIT_FCALL                                               'array_keys'
         46        SEND_VAL                                                 1
         47        DO_ICALL                                                 
         48      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2Fs6b9G%3A56%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/s6b9G
function name:  {closure}
number of ops:  16
compiled vars:  !0 = $no, !1 = $str, !2 = $file, !3 = $line, !4 = $varList
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
          4        RECV                                             !4      
   58     5        NEW                                              $5      'ePHPException'
          6        SEND_VAR_EX                                              !1
          7        SEND_VAL_EX                                              0
          8        SEND_VAR_EX                                              !0
          9        SEND_VAR_EX                                              !2
         10        SEND_VAR_EX                                              !3
         11        SEND_VAL_EX                                              null
         12        SEND_VAR_EX                                              !4
         13        DO_FCALL                                      0          
         14      > THROW                                         0          $5
   59    15*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fs6b9G%3A56%240

Function %00%7Bclosure%7D%2Fin%2Fs6b9G%3A61%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 22
Branch analysis from position: 6
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/s6b9G
function name:  {closure}
number of ops:  23
compiled vars:  !0 = $error
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   INIT_FCALL                                               'error_get_last'
          1        DO_ICALL                                         $1      
          2        ASSIGN                                                   !0, $1
   63     3        FETCH_DIM_R                                      ~3      !0, 'type'
          4        IS_IDENTICAL                                             ~3, 1
          5      > JMPZ                                                     ~4, ->22
   64     6    >   NEW                                              $5      'ePHPException'
          7        CHECK_FUNC_ARG                                           
          8        FETCH_DIM_FUNC_ARG                               $6      !0, 'message'
          9        SEND_FUNC_ARG                                            $6
         10        SEND_VAL_EX                                              0
         11        CHECK_FUNC_ARG                                           
         12        FETCH_DIM_FUNC_ARG                               $7      !0, 'type'
         13        SEND_FUNC_ARG                                            $7
         14        CHECK_FUNC_ARG                                           
         15        FETCH_DIM_FUNC_ARG                               $8      !0, 'file'
         16        SEND_FUNC_ARG                                            $8
         17        CHECK_FUNC_ARG                                           
         18        FETCH_DIM_FUNC_ARG                               $9      !0, 'line'
         19        SEND_FUNC_ARG                                            $9
         20        DO_FCALL                                      0          
         21      > THROW                                         0          $5
   65    22    > > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fs6b9G%3A61%241

Function %00%7Bclosure%7D%2Fin%2Fs6b9G%3A69%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/s6b9G
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $exception
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   RECV                                             !0      
   70     1        INIT_FCALL                                               'header'
          2        SEND_VAL                                                 'Content-Type%3A+text%2Fplant%3B+charset%3DUTF-8'
          3        DO_ICALL                                                 
   72     4        INIT_FCALL                                               'header'
          5        SEND_VAL                                                 'HTTP%2F1.1+500+Internal+Server+Error'
          6        DO_ICALL                                         $2      
          7      > EXIT                                                     $2
   73     8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fs6b9G%3A69%242

Function %00%7Bclosure%7D%2Fin%2Fs6b9G%3A78%243:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 28
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 27
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 27
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 27
2 jumps found. (Code = 77) Position 1 = 30, Position 2 = 51
Branch analysis from position: 30
2 jumps found. (Code = 78) Position 1 = 31, Position 2 = 51
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 51
2 jumps found. (Code = 46) Position 1 = 82, Position 2 = 84
Branch analysis from position: 82
2 jumps found. (Code = 43) Position 1 = 85, Position 2 = 90
Branch analysis from position: 85
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 90
Branch analysis from position: 84
Branch analysis from position: 51
Branch analysis from position: 27
Branch analysis from position: 28
filename:       /in/s6b9G
function name:  {closure}
number of ops:  91
compiled vars:  !0 = $exception, !1 = $msg, !2 = $traceline, !3 = $trace, !4 = $stackPoint, !5 = $key, !6 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   78     0  E >   RECV                                             !0      
   79     1        ECHO                                                     '---'
   81     2        INIT_FCALL                                               'header'
          3        SEND_VAL                                                 'Content-Type%3A+text%2Fplant%3B+charset%3DUTF-8'
          4        DO_ICALL                                                 
   84     5        ASSIGN                                                   !1, 'Exception+%60%25s%60%3A+%25s%0AStack+trace%3A%0A%25s%0A++thrown+in+%25s+on+line+%25s'
   86     6        ASSIGN                                                   !2, '%23%25s+%25s+%28%25s%29%3A+%25s%28%25s%29'
   89     7        INIT_METHOD_CALL                                         !0, 'getTrace'
          8        DO_FCALL                                      0  $10     
          9        ASSIGN                                                   !3, $10
   92    10        FETCH_CONSTANT                                   ~12     'eRunMode'
         11        FETCH_CONSTANT                                   ~13     'eDebug'
         12        IS_SMALLER                                               ~12, ~13
         13      > JMPZ                                                     ~14, ->28
   93    14    > > FE_RESET_R                                       $15     !3, ->27
         15    > > FE_FETCH_R                                       ~16     $15, !4, ->27
         16    >   ASSIGN                                                   !5, ~16
   94    17        INIT_FCALL                                               'array_map'
         18        SEND_VAL                                                 'gettype'
         19        FETCH_DIM_R                                      ~20     !3, !5
         20        FETCH_DIM_R                                      ~21     ~20, 'args'
         21        SEND_VAL                                                 ~21
         22        DO_ICALL                                         $22     
         23        FETCH_DIM_W                                      $18     !3, !5
         24        ASSIGN_DIM                                               $18, 'args'
         25        OP_DATA                                                  $22
   93    26      > JMP                                                      ->15
         27    >   FE_FREE                                                  $15
   96    28    >   ASSIGN                                                   !6, <array>
   99    29      > FE_RESET_R                                       $24     !3, ->51
         30    > > FE_FETCH_R                                       ~25     $24, !4, ->51
         31    >   ASSIGN                                                   !5, ~25
  100    32        INIT_FCALL                                               'sprintf'
  101    33        SEND_VAR                                                 !2
  102    34        SEND_VAR                                                 !5
  103    35        FETCH_DIM_R                                      ~28     !4, 'file'
         36        SEND_VAL                                                 ~28
  104    37        FETCH_DIM_R                                      ~29     !4, 'line'
         38        SEND_VAL                                                 ~29
  105    39        FETCH_DIM_R                                      ~30     !4, 'function'
         40        SEND_VAL                                                 ~30
  106    41        INIT_FCALL                                               'implode'
         42        SEND_VAL                                                 '%2C+'
         43        FETCH_DIM_R                                      ~31     !4, 'args'
         44        SEND_VAL                                                 ~31
         45        DO_ICALL                                         $32     
         46        SEND_VAR                                                 $32
         47        DO_ICALL                                         $33     
  100    48        ASSIGN_DIM                                               !6
  106    49        OP_DATA                                                  $33
   99    50      > JMP                                                      ->30
         51    >   FE_FREE                                                  $24
  109    52        PRE_INC                                          ~35     !5
         53        CONCAT                                           ~36     '%23', ~35
         54        CONCAT                                           ~37     ~36, '+%7Bmain%7D'
         55        ASSIGN_DIM                                               !6
         56        OP_DATA                                                  ~37
  112    57        INIT_FCALL                                               'sprintf'
  113    58        SEND_VAR                                                 !1
  114    59        GET_CLASS                                        ~38     !0
         60        SEND_VAL                                                 ~38
  115    61        INIT_METHOD_CALL                                         !0, 'getMessage'
         62        DO_FCALL                                      0  $39     
         63        SEND_VAR                                                 $39
  116    64        INIT_FCALL                                               'implode'
         65        SEND_VAL                                                 '%0A'
         66        SEND_VAR                                                 !6
         67        DO_ICALL                                         $40     
         68        SEND_VAR                                                 $40
  117    69        INIT_METHOD_CALL                                         !0, 'getFile'
         70        DO_FCALL                                      0  $41     
         71        SEND_VAR                                                 $41
  118    72        INIT_METHOD_CALL                                         !0, 'getLine'
         73        DO_FCALL                                      0  $42     
         74        SEND_VAR                                                 $42
         75        DO_ICALL                                         $43     
  112    76        ASSIGN                                                   !1, $43
  122    77        ECHO                                                     !1
  125    78        FETCH_CONSTANT                                   ~45     'eRunMode'
         79        FETCH_CONSTANT                                   ~46     'eDebug'
         80        IS_SMALLER_OR_EQUAL                              ~47     ~46, ~45
         81      > JMPZ_EX                                          ~47     ~47, ->84
         82    >   INSTANCEOF                                       ~48     !0, 'ePHPException'
         83        BOOL                                             ~47     ~48
         84    > > JMPZ                                                     ~47, ->90
  126    85    >   INIT_FCALL                                               'print_r'
         86        INIT_METHOD_CALL                                         !0, 'getVarList'
         87        DO_FCALL                                      0  $49     
         88        SEND_VAR                                                 $49
         89        DO_ICALL                                                 
  127    90    > > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fs6b9G%3A78%243

Class ePHPException:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/s6b9G
function name:  __construct
number of ops:  21
compiled vars:  !0 = $message, !1 = $code, !2 = $severity, !3 = $filename, !4 = $lineno, !5 = $previous, !6 = $varList
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV_INIT                                        !0      ''
          1        RECV_INIT                                        !1      0
          2        RECV_INIT                                        !2      1
          3        RECV_INIT                                        !3      '%2Fin%2Fs6b9G'
          4        RECV_INIT                                        !4      34
          5        RECV_INIT                                        !5      null
          6        RECV_INIT                                        !6      <array>
   36     7        ASSIGN_OBJ                                               'severity'
          8        OP_DATA                                                  !2
   37     9        ASSIGN_OBJ                                               'file'
         10        OP_DATA                                                  !3
   38    11        ASSIGN_OBJ                                               'line'
         12        OP_DATA                                                  !4
   39    13        ASSIGN_OBJ                                               'varList'
         14        OP_DATA                                                  !6
   42    15        INIT_STATIC_METHOD_CALL                                  
         16        SEND_VAR_EX                                              !0
         17        SEND_VAR_EX                                              !1
         18        SEND_VAR_EX                                              !5
         19        DO_FCALL                                      0          
   43    20      > RETURN                                                   null

End of function __construct

Function getseverity:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/s6b9G
function name:  getSeverity
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   FETCH_OBJ_R                                      ~0      'severity'
          1      > RETURN                                                   ~0
   48     2*     > RETURN                                                   null

End of function getseverity

Function getvarlist:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/s6b9G
function name:  getVarList
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   FETCH_OBJ_R                                      ~0      'varList'
          1      > RETURN                                                   ~0
   53     2*     > RETURN                                                   null

End of function getvarlist

End of class ePHPException.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.2 ms | 1408 KiB | 37 Q