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(); if (false === $this->caughtOutput) { ob_end_clean(); echo 456; echo strlen($this->caughtOutput); } 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/EPvYm
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          
   99     9    >   INIT_STATIC_METHOD_CALL                                  'Symfony%5CComponent%5CDebug%5CExceptionHandler', 'register'
         10        DO_FCALL                                      0          
  101    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/EPvYm
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/EPvYm
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/EPvYm
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
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 25
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 39
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 60
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 51, Position 2 = 53
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 60
Branch analysis from position: 60
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
Branch analysis from position: 60
Branch analysis from position: 39
Branch analysis from position: 25
Found catch point at position: 56
Branch analysis from position: 56
2 jumps found. (Code = 107) Position 1 = 57, Position 2 = -2
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 60
Branch analysis from position: 59
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 60
filename:       /in/EPvYm
function name:  handle
number of ops:  61
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        FETCH_OBJ_R                                      ~9      'caughtOutput'
         14        TYPE_CHECK                                    4          ~9
         15      > JMPZ                                                     ~10, ->25
   50    16    >   INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CDebug%5Cob_end_clean'
         17        DO_FCALL                                      0          
   51    18        ECHO                                                     456
   52    19        INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CDebug%5Cstrlen'
         20        CHECK_FUNC_ARG                                           
         21        FETCH_OBJ_FUNC_ARG                               $12     'caughtOutput'
         22        SEND_FUNC_ARG                                            $12
         23        DO_FCALL                                      0  $13     
         24        ECHO                                                     $13
   54    25    >   FETCH_OBJ_IS                                     ~14     'caughtOutput'
         26        ISSET_ISEMPTY_DIM_OBJ                         0          ~14, 0
         27      > JMPZ                                                     ~15, ->39
   55    28    >   INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CDebug%5Cob_start'
         29        FETCH_THIS                                       ~16     
         30        INIT_ARRAY                                       ~17     ~16
         31        ADD_ARRAY_ELEMENT                                ~17     'cleanOutput'
         32        SEND_VAL_EX                                              ~17
         33        DO_FCALL                                      0          
   56    34        FETCH_OBJ_R                                      ~19     'caughtOutput'
         35        ECHO                                                     ~19
   57    36        INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CDebug%5Cob_get_length'
         37        DO_FCALL                                      0  $20     
         38        ASSIGN                                                   !1, $20
   59    39    >   ASSIGN_OBJ                                               'caughtOutput'
         40        OP_DATA                                                  0
   61    41        ISSET_ISEMPTY_PROP_OBJ                           ~23     'handler'
         42        BOOL_NOT                                         ~24     ~23
         43      > JMPZ                                                     ~24, ->60
   63    44    >   INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CDebug%5Ccall_user_func'
         45        CHECK_FUNC_ARG                                           
         46        FETCH_OBJ_FUNC_ARG                               $25     'handler'
         47        SEND_FUNC_ARG                                            $25
         48        SEND_VAR_EX                                              !0
         49        DO_FCALL                                      0          
   65    50      > JMPZ                                                     !1, ->53
   66    51    >   ASSIGN_OBJ                                               'caughtOutput'
         52        OP_DATA                                                  !1
   68    53    >   INIT_NS_FCALL_BY_NAME                                    'Symfony%5CComponent%5CDebug%5Cob_end_flush'
         54        DO_FCALL                                      0          
         55      > JMP                                                      ->60
   69    56  E > > CATCH                                       last         'Exception'
   70    57    >   BOOL_NOT                                         ~29     !1
         58      > JMPZ                                                     ~29, ->60
   72    59    > > THROW                                         0          !0
   76    60    > > 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/EPvYm
function name:  catchOutput
number of ops:  5
compiled vars:  !0 = $buffer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   78     0  E >   RECV                                             !0      
   80     1        ASSIGN_OBJ                                               'caughtOutput'
          2        OP_DATA                                                  !0
   82     3      > RETURN                                                   ''
   83     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/EPvYm
function name:  cleanOutput
number of ops:  17
compiled vars:  !0 = $buffer, !1 = $cleanBuffer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   85     0  E >   RECV                                             !0      
   87     1        FETCH_OBJ_R                                      ~2      'caughtOutput'
          2      > JMPZ                                                     ~2, ->15
   89     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
   90    12        ISSET_ISEMPTY_DIM_OBJ                         0          !1, 0
         13      > JMPZ                                                     ~6, ->15
   91    14    >   ASSIGN                                                   !0, !1
   95    15    > > RETURN                                                   !0
   96    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:
171.9 ms | 1412 KiB | 35 Q