3v4l.org

run code in 300+ PHP versions simultaneously
<?php // 为避免污染全局命名空间,已对所有标识符加 `e` 前缀 /** * 运行模式 * * debug 调试模式, 会开启详细的日志记录和错误提示 * * default 默认模式, 会输出错误提示 * * production 生产模式, 不会执行任何额外操作, 最高效地执行代码 */ 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); }); 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 { set_exception_handler(function(Exception $exception) { // 暂时我们只打算以纯文本的形式展示信息 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) {echo 11111;} print_r($exception->getVarList()); }); } class TypeException extends Exception{} function repeat($argInt, $argString) { if(is_int($argInt) && is_int($argString)) return str_repeat($argString, $argInt); else throw new TypeException("Type Error"); } function call($func, $arg1, $arg2) { $func($arg1, $arg2); } function errorFunc() { dontExistFunction(); } // 错误1: call("repeat", "Hello World", 1234); // 错误2: //call(new TypeException, 12, 34); // 错误3: //call("errorFunc", 0, 0);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 21
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 34
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
Branch analysis from position: 14
filename:       /in/eqHi6
function name:  (null)
number of ops:  44
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   DECLARE_CONST                                            'eDebug', 2
   13     1        DECLARE_CONST                                            'eDefault', 1
   14     2        DECLARE_CONST                                            'eProduction', 0
   16     3        DECLARE_CONST                                            'eRunMode', <const ast>
   19     4        INIT_FCALL                                               'error_reporting'
          5        SEND_VAL                                                 0
          6        DO_ICALL                                                 
   21     7        FETCH_CONSTANT                                   ~1      'eRunMode'
          8        FETCH_CONSTANT                                   ~2      'eDefault'
          9        IS_SMALLER_OR_EQUAL                                      ~2, ~1
         10      > JMPZ                                                     ~3, ->14
   22    11    >   INIT_FCALL                                               'error_reporting'
         12        SEND_VAL                                                 5
         13        DO_ICALL                                                 
   24    14    >   FETCH_CONSTANT                                   ~5      'eRunMode'
         15        FETCH_CONSTANT                                   ~6      'eDebug'
         16        IS_SMALLER_OR_EQUAL                                      ~6, ~5
         17      > JMPZ                                                     ~7, ->21
   25    18    >   INIT_FCALL                                               'error_reporting'
         19        SEND_VAL                                                 32767
         20        DO_ICALL                                                 
   53    21    >   INIT_FCALL                                               'set_error_handler'
         22        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FeqHi6%3A53%240'
   56    23        SEND_VAL                                                 ~9
         24        DO_ICALL                                                 
   58    25        FETCH_CONSTANT                                   ~11     'eRunMode'
         26        FETCH_CONSTANT                                   ~12     'eProduction'
         27        IS_SMALLER_OR_EQUAL                                      ~11, ~12
         28      > JMPZ                                                     ~13, ->34
   60    29    >   INIT_FCALL                                               'set_exception_handler'
         30        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FeqHi6%3A60%241'
   64    31        SEND_VAL                                                 ~14
         32        DO_ICALL                                                 
         33      > JMP                                                      ->38
   68    34    >   INIT_FCALL                                               'set_exception_handler'
         35        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FeqHi6%3A68%242'
  117    36        SEND_VAL                                                 ~16
         37        DO_ICALL                                                 
  141    38    >   INIT_FCALL                                               'call'
         39        SEND_VAL                                                 'repeat'
         40        SEND_VAL                                                 'Hello+World'
         41        SEND_VAL                                                 1234
         42        DO_FCALL                                      0          
  145    43      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FeqHi6%3A53%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/eqHi6
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
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
          4        RECV                                             !4      
   55     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
   56    15*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FeqHi6%3A53%240

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

End of function %00%7Bclosure%7D%2Fin%2FeqHi6%3A60%241

Function %00%7Bclosure%7D%2Fin%2FeqHi6%3A68%242:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 27
Branch analysis from position: 13
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 26
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 26
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 26
2 jumps found. (Code = 77) Position 1 = 29, Position 2 = 50
Branch analysis from position: 29
2 jumps found. (Code = 78) Position 1 = 30, Position 2 = 50
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Branch analysis from position: 50
2 jumps found. (Code = 46) Position 1 = 81, Position 2 = 83
Branch analysis from position: 81
2 jumps found. (Code = 43) Position 1 = 84, Position 2 = 85
Branch analysis from position: 84
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 85
Branch analysis from position: 83
Branch analysis from position: 50
Branch analysis from position: 26
Branch analysis from position: 27
filename:       /in/eqHi6
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
-------------------------------------------------------------------------------------
   68     0  E >   RECV                                             !0      
   70     1        INIT_FCALL                                               'header'
          2        SEND_VAL                                                 'Content-Type%3A+text%2Fplant%3B+charset%3DUTF-8'
          3        DO_ICALL                                                 
   73     4        ASSIGN                                                   !1, 'Exception+%60%25s%60%3A+%25s%0AStack+trace%3A%0A%25s%0A++thrown+in+%25s+on+line+%25s'
   75     5        ASSIGN                                                   !2, '%23%25s+%25s+%28%25s%29%3A+%25s%28%25s%29'
   78     6        INIT_METHOD_CALL                                         !0, 'getTrace'
          7        DO_FCALL                                      0  $10     
          8        ASSIGN                                                   !3, $10
   81     9        FETCH_CONSTANT                                   ~12     'eRunMode'
         10        FETCH_CONSTANT                                   ~13     'eDebug'
         11        IS_SMALLER                                               ~12, ~13
         12      > JMPZ                                                     ~14, ->27
   82    13    > > FE_RESET_R                                       $15     !3, ->26
         14    > > FE_FETCH_R                                       ~16     $15, !4, ->26
         15    >   ASSIGN                                                   !5, ~16
   83    16        INIT_FCALL                                               'array_map'
         17        SEND_VAL                                                 'gettype'
         18        FETCH_DIM_R                                      ~20     !3, !5
         19        FETCH_DIM_R                                      ~21     ~20, 'args'
         20        SEND_VAL                                                 ~21
         21        DO_ICALL                                         $22     
         22        FETCH_DIM_W                                      $18     !3, !5
         23        ASSIGN_DIM                                               $18, 'args'
         24        OP_DATA                                                  $22
   82    25      > JMP                                                      ->14
         26    >   FE_FREE                                                  $15
   85    27    >   ASSIGN                                                   !6, <array>
   88    28      > FE_RESET_R                                       $24     !3, ->50
         29    > > FE_FETCH_R                                       ~25     $24, !4, ->50
         30    >   ASSIGN                                                   !5, ~25
   89    31        INIT_FCALL                                               'sprintf'
   90    32        SEND_VAR                                                 !2
   91    33        SEND_VAR                                                 !5
   92    34        FETCH_DIM_R                                      ~28     !4, 'file'
         35        SEND_VAL                                                 ~28
   93    36        FETCH_DIM_R                                      ~29     !4, 'line'
         37        SEND_VAL                                                 ~29
   94    38        FETCH_DIM_R                                      ~30     !4, 'function'
         39        SEND_VAL                                                 ~30
   95    40        INIT_FCALL                                               'implode'
         41        SEND_VAL                                                 '%2C+'
         42        FETCH_DIM_R                                      ~31     !4, 'args'
         43        SEND_VAL                                                 ~31
         44        DO_ICALL                                         $32     
         45        SEND_VAR                                                 $32
         46        DO_ICALL                                         $33     
   89    47        ASSIGN_DIM                                               !6
   95    48        OP_DATA                                                  $33
   88    49      > JMP                                                      ->29
         50    >   FE_FREE                                                  $24
   98    51        PRE_INC                                          ~35     !5
         52        CONCAT                                           ~36     '%23', ~35
         53        CONCAT                                           ~37     ~36, '+%7Bmain%7D'
         54        ASSIGN_DIM                                               !6
         55        OP_DATA                                                  ~37
  101    56        INIT_FCALL                                               'sprintf'
  102    57        SEND_VAR                                                 !1
  103    58        GET_CLASS                                        ~38     !0
         59        SEND_VAL                                                 ~38
  104    60        INIT_METHOD_CALL                                         !0, 'getMessage'
         61        DO_FCALL                                      0  $39     
         62        SEND_VAR                                                 $39
  105    63        INIT_FCALL                                               'implode'
         64        SEND_VAL                                                 '%0A'
         65        SEND_VAR                                                 !6
         66        DO_ICALL                                         $40     
         67        SEND_VAR                                                 $40
  106    68        INIT_METHOD_CALL                                         !0, 'getFile'
         69        DO_FCALL                                      0  $41     
         70        SEND_VAR                                                 $41
  107    71        INIT_METHOD_CALL                                         !0, 'getLine'
         72        DO_FCALL                                      0  $42     
         73        SEND_VAR                                                 $42
         74        DO_ICALL                                         $43     
  101    75        ASSIGN                                                   !1, $43
  111    76        ECHO                                                     !1
  114    77        FETCH_CONSTANT                                   ~45     'eRunMode'
         78        FETCH_CONSTANT                                   ~46     'eDebug'
         79        IS_SMALLER_OR_EQUAL                              ~47     ~46, ~45
         80      > JMPZ_EX                                          ~47     ~47, ->83
         81    >   INSTANCEOF                                       ~48     !0, 'ePHPException'
         82        BOOL                                             ~47     ~48
         83    > > JMPZ                                                     ~47, ->85
  115    84    >   ECHO                                                     11111
  116    85    >   INIT_FCALL                                               'print_r'
         86        INIT_METHOD_CALL                                         !0, 'getVarList'
         87        DO_FCALL                                      0  $49     
         88        SEND_VAR                                                 $49
         89        DO_ICALL                                                 
  117    90      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FeqHi6%3A68%242

Function repeat:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 13
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 6
filename:       /in/eqHi6
function name:  repeat
number of ops:  18
compiled vars:  !0 = $argInt, !1 = $argString
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  122     0  E >   RECV                                             !0      
          1        RECV                                             !1      
  124     2        TYPE_CHECK                                   16  ~2      !0
          3      > JMPZ_EX                                          ~2      ~2, ->6
          4    >   TYPE_CHECK                                   16  ~3      !1
          5        BOOL                                             ~2      ~3
          6    > > JMPZ                                                     ~2, ->13
  125     7    >   INIT_FCALL                                               'str_repeat'
          8        SEND_VAR                                                 !1
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $4      
         11      > RETURN                                                   $4
         12*       JMP                                                      ->17
  127    13    >   NEW                                              $5      'TypeException'
         14        SEND_VAL_EX                                              'Type+Error'
         15        DO_FCALL                                      0          
         16      > THROW                                         0          $5
  128    17*     > RETURN                                                   null

End of function repeat

Function call:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eqHi6
function name:  call
number of ops:  8
compiled vars:  !0 = $func, !1 = $arg1, !2 = $arg2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  130     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
  132     3        INIT_DYNAMIC_CALL                                        !0
          4        SEND_VAR_EX                                              !1
          5        SEND_VAR_EX                                              !2
          6        DO_FCALL                                      0          
  133     7      > RETURN                                                   null

End of function call

Function errorfunc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eqHi6
function name:  errorFunc
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  137     0  E >   INIT_FCALL_BY_NAME                                       'dontExistFunction'
          1        DO_FCALL                                      0          
  138     2      > RETURN                                                   null

End of function errorfunc

Class ePHPException:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eqHi6
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
-------------------------------------------------------------------------------------
   32     0  E >   RECV_INIT                                        !0      ''
          1        RECV_INIT                                        !1      0
          2        RECV_INIT                                        !2      1
          3        RECV_INIT                                        !3      '%2Fin%2FeqHi6'
          4        RECV_INIT                                        !4      32
          5        RECV_INIT                                        !5      null
          6        RECV_INIT                                        !6      <array>
   34     7        ASSIGN_OBJ                                               'severity'
          8        OP_DATA                                                  !2
   35     9        ASSIGN_OBJ                                               'file'
         10        OP_DATA                                                  !3
   36    11        ASSIGN_OBJ                                               'line'
         12        OP_DATA                                                  !4
   37    13        ASSIGN_OBJ                                               'varList'
         14        OP_DATA                                                  !6
   39    15        INIT_STATIC_METHOD_CALL                                  
         16        SEND_VAR_EX                                              !0
         17        SEND_VAR_EX                                              !1
         18        SEND_VAR_EX                                              !5
         19        DO_FCALL                                      0          
   40    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/eqHi6
function name:  getSeverity
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   FETCH_OBJ_R                                      ~0      'severity'
          1      > RETURN                                                   ~0
   45     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/eqHi6
function name:  getVarList
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   FETCH_OBJ_R                                      ~0      'varList'
          1      > RETURN                                                   ~0
   50     2*     > RETURN                                                   null

End of function getvarlist

End of class ePHPException.

Class TypeException: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.05 ms | 1422 KiB | 32 Q