3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Symfony\Component\Debug; if (!defined('ENT_SUBSTITUTE')) { define('ENT_SUBSTITUTE', 8); } class ExceptionHandler { private $debug; private $charset; private $handler; private $caughtOutput = 0; public function __construct($debug = true, $charset = 'UTF-8') { $this->debug = $debug; $this->charset = $charset; } public static function register($debug = true) { $handler = new static($debug); set_exception_handler(array($handler, 'handle')); return $handler; } public function setHandler($handler) { if (isset($handler) && !is_callable($handler)) { throw new \LogicException('The exception handler must be a valid PHP callable.'); } $old = $this->handler; $this->handler = $handler; return $old; } public function handle(\Exception $exception) { $caughtOutput = 0; $this->caughtOutput = false; ob_start(array($this, 'catchOutput')); echo $exception->getMessage(); while (false === $this->caughtOutput) { ob_get_contents(); $caughtOutput = $this->caughtOutput; ob_end_clean(); echo $this->caughtOutput = $caughtOutput; $caughtOutput = 0; // Empty loop, everything is in the condition } if (isset($this->caughtOutput[0])) { ob_start(array($this, 'cleanOutput')); echo $this->caughtOutput; $caughtOutput = ob_get_length(); } $this->caughtOutput = 0; if (!empty($this->handler)) { try { call_user_func($this->handler, $exception); if ($caughtOutput) { $this->caughtOutput = $caughtOutput; } ob_end_flush(); } catch (\Exception $e) { if (!$caughtOutput) { // All handlers failed. Let PHP handle that now. throw $exception; } } } } public function catchOutput($buffer) { $this->caughtOutput = $buffer; return ''; } public function cleanOutput($buffer) { if ($this->caughtOutput) { // use substr_replace() instead of substr() for mbstring overloading resistance $cleanBuffer = substr_replace($buffer, '', 0, $this->caughtOutput); if (isset($cleanBuffer[0])) { $buffer = $cleanBuffer; } } return $buffer; } } ExceptionHandler::register(); throw new \Exception('foo msg');
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 9
filename:       /in/tpGpD
function name:  (null)
number of ops:  16
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CDebug%5Cdefined'
          1        SEND_VAL_EX                                              'ENT_SUBSTITUTE'
          2        DO_FCALL                                      0  $0      
          3        BOOL_NOT                                         ~1      $0
          4      > JMPZ                                                     ~1, ->9
    6     5    >   INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CDebug%5Cdefine'
          6        SEND_VAL_EX                                              'ENT_SUBSTITUTE'
          7        SEND_VAL_EX                                              8
          8        DO_FCALL                                      0          
  102     9    >   INIT_STATIC_METHOD_CALL                                  'Symfony%5CComponent%5CDebug%5CExceptionHandler', 'register'
         10        DO_FCALL                                      0          
  104    11        NEW                                              $4      'Exception'
         12        SEND_VAL_EX                                              'foo+msg'
         13        DO_FCALL                                      0          
         14      > THROW                                         0          $4
         15*     > RETURN                                                   1

Class Symfony\Component\Debug\ExceptionHandler:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tpGpD
function name:  __construct
number of ops:  7
compiled vars:  !0 = $debug, !1 = $charset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV_INIT                                        !0      <true>
          1        RECV_INIT                                        !1      'UTF-8'
   18     2        ASSIGN_OBJ                                               'debug'
          3        OP_DATA                                                  !0
   19     4        ASSIGN_OBJ                                               'charset'
          5        OP_DATA                                                  !1
   20     6      > RETURN                                                   null

End of function __construct

Function register:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tpGpD
function name:  register
number of ops:  12
compiled vars:  !0 = $debug, !1 = $handler
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV_INIT                                        !0      <true>
   24     1        NEW                          static              $2      
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $2
   26     5        INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CDebug%5Cset_exception_handler'
          6        INIT_ARRAY                                       ~5      !1
          7        ADD_ARRAY_ELEMENT                                ~5      'handle'
          8        SEND_VAL_EX                                              ~5
          9        DO_FCALL                                      0          
   28    10      > RETURN                                                   !1
   29    11*     > RETURN                                                   null

End of function register

Function sethandler:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 13
Branch analysis from position: 9
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/tpGpD
function name:  setHandler
number of ops:  19
compiled vars:  !0 = $handler, !1 = $old
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   33     1        ISSET_ISEMPTY_CV                                 ~2      !0
          2      > JMPZ_EX                                          ~2      ~2, ->8
          3    >   INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CDebug%5Cis_callable'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0  $3      
          6        BOOL_NOT                                         ~4      $3
          7        BOOL                                             ~2      ~4
          8    > > JMPZ                                                     ~2, ->13
   34     9    >   NEW                                              $5      'LogicException'
         10        SEND_VAL_EX                                              'The+exception+handler+must+be+a+valid+PHP+callable.'
         11        DO_FCALL                                      0          
         12      > THROW                                         0          $5
   36    13    >   FETCH_OBJ_R                                      ~7      'handler'
         14        ASSIGN                                                   !1, ~7
   37    15        ASSIGN_OBJ                                               'handler'
         16        OP_DATA                                                  !0
   39    17      > RETURN                                                   !1
   40    18*     > RETURN                                                   null

End of function sethandler

Function handle:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 14
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 41
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 62
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 55
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 62
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 55
Branch analysis from position: 62
Branch analysis from position: 41
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 14
Branch analysis from position: 27
Branch analysis from position: 14
Found catch point at position: 58
Branch analysis from position: 58
2 jumps found. (Code = 107) Position 1 = 59, Position 2 = -2
Branch analysis from position: 59
2 jumps found. (Code = 43) Position 1 = 61, Position 2 = 62
Branch analysis from position: 61
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 62
filename:       /in/tpGpD
function name:  handle
number of ops:  63
compiled vars:  !0 = $exception, !1 = $caughtOutput, !2 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV                                             !0      
   44     1        ASSIGN                                                   !1, 0
   46     2        ASSIGN_OBJ                                               'caughtOutput'
          3        OP_DATA                                                  <false>
   47     4        INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CDebug%5Cob_start'
          5        FETCH_THIS                                       ~5      
          6        INIT_ARRAY                                       ~6      ~5
          7        ADD_ARRAY_ELEMENT                                ~6      'catchOutput'
          8        SEND_VAL_EX                                              ~6
          9        DO_FCALL                                      0          
   48    10        INIT_METHOD_CALL                                         !0, 'getMessage'
         11        DO_FCALL                                      0  $8      
         12        ECHO                                                     $8
   49    13      > JMP                                                      ->24
   50    14    >   INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CDebug%5Cob_get_contents'
         15        DO_FCALL                                      0          
   51    16        FETCH_OBJ_R                                      ~10     'caughtOutput'
         17        ASSIGN                                                   !1, ~10
   52    18        INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CDebug%5Cob_end_clean'
         19        DO_FCALL                                      0          
   53    20        ASSIGN_OBJ                                       ~13     'caughtOutput'
         21        OP_DATA                                                  !1
         22        ECHO                                                     ~13
   54    23        ASSIGN                                                   !1, 0
   49    24    >   FETCH_OBJ_R                                      ~15     'caughtOutput'
         25        TYPE_CHECK                                    4          ~15
         26      > JMPNZ                                                    ~16, ->14
   57    27    >   FETCH_OBJ_IS                                     ~17     'caughtOutput'
         28        ISSET_ISEMPTY_DIM_OBJ                         0          ~17, 0
         29      > JMPZ                                                     ~18, ->41
   58    30    >   INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CDebug%5Cob_start'
         31        FETCH_THIS                                       ~19     
         32        INIT_ARRAY                                       ~20     ~19
         33        ADD_ARRAY_ELEMENT                                ~20     'cleanOutput'
         34        SEND_VAL_EX                                              ~20
         35        DO_FCALL                                      0          
   59    36        FETCH_OBJ_R                                      ~22     'caughtOutput'
         37        ECHO                                                     ~22
   60    38        INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CDebug%5Cob_get_length'
         39        DO_FCALL                                      0  $23     
         40        ASSIGN                                                   !1, $23
   62    41    >   ASSIGN_OBJ                                               'caughtOutput'
         42        OP_DATA                                                  0
   64    43        ISSET_ISEMPTY_PROP_OBJ                           ~26     'handler'
         44        BOOL_NOT                                         ~27     ~26
         45      > JMPZ                                                     ~27, ->62
   66    46    >   INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CDebug%5Ccall_user_func'
         47        CHECK_FUNC_ARG                                           
         48        FETCH_OBJ_FUNC_ARG                               $28     'handler'
         49        SEND_FUNC_ARG                                            $28
         50        SEND_VAR_EX                                              !0
         51        DO_FCALL                                      0          
   68    52      > JMPZ                                                     !1, ->55
   69    53    >   ASSIGN_OBJ                                               'caughtOutput'
         54        OP_DATA                                                  !1
   71    55    >   INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CDebug%5Cob_end_flush'
         56        DO_FCALL                                      0          
         57      > JMP                                                      ->62
   72    58  E > > CATCH                                       last         'Exception'
   73    59    >   BOOL_NOT                                         ~32     !1
         60      > JMPZ                                                     ~32, ->62
   75    61    > > THROW                                         0          !0
   79    62    > > RETURN                                                   null

End of function handle

Function catchoutput:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tpGpD
function name:  catchOutput
number of ops:  5
compiled vars:  !0 = $buffer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   81     0  E >   RECV                                             !0      
   83     1        ASSIGN_OBJ                                               'caughtOutput'
          2        OP_DATA                                                  !0
   85     3      > RETURN                                                   ''
   86     4*     > RETURN                                                   null

End of function catchoutput

Function cleanoutput:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 15
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 15
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
Branch analysis from position: 15
filename:       /in/tpGpD
function name:  cleanOutput
number of ops:  17
compiled vars:  !0 = $buffer, !1 = $cleanBuffer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   88     0  E >   RECV                                             !0      
   90     1        FETCH_OBJ_R                                      ~2      'caughtOutput'
          2      > JMPZ                                                     ~2, ->15
   92     3    >   INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CDebug%5Csubstr_replace'
          4        SEND_VAR_EX                                              !0
          5        SEND_VAL_EX                                              ''
          6        SEND_VAL_EX                                              0
          7        CHECK_FUNC_ARG                                           
          8        FETCH_OBJ_FUNC_ARG                               $3      'caughtOutput'
          9        SEND_FUNC_ARG                                            $3
         10        DO_FCALL                                      0  $4      
         11        ASSIGN                                                   !1, $4
   93    12        ISSET_ISEMPTY_DIM_OBJ                         0          !1, 0
         13      > JMPZ                                                     ~6, ->15
   94    14    >   ASSIGN                                                   !0, !1
   98    15    > > RETURN                                                   !0
   99    16*     > RETURN                                                   null

End of function cleanoutput

End of class Symfony\Component\Debug\ExceptionHandler.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.07 ms | 1412 KiB | 35 Q