3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait ExceptionFixer { public static function throw(self $exception): self { $exception->file = $exception->getTrace()[0]['file']; $exception->line = $exception->getTrace()[0]['line']; return $exception; } } class MyException extends Exception { use ExceptionFixer; public static function create(): self { $self = new MyException('Custom exception'); return self::throw($self); } } try { throw MyException::create(); } catch (Exception $exception) { echo $exception->getLine() . PHP_EOL; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
Found catch point at position: 5
Branch analysis from position: 5
2 jumps found. (Code = 107) Position 1 = 6, Position 2 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HlZDW
function name:  (null)
number of ops:  11
compiled vars:  !0 = $exception
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   DECLARE_CLASS                                            'myexception', 'exception'
   17     1        INIT_STATIC_METHOD_CALL                                  'MyException', 'create'
          2        DO_FCALL                                      0  $1      
          3      > THROW                                         0          $1
          4*       JMP                                                      ->10
   18     5  E > > CATCH                                       last         'Exception'
   19     6    >   INIT_METHOD_CALL                                         !0, 'getLine'
          7        DO_FCALL                                      0  $2      
          8        CONCAT                                           ~3      $2, '%0A'
          9        ECHO                                                     ~3
   20    10      > RETURN                                                   1

Class ExceptionFixer:
Function throw:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HlZDW
function name:  throw
number of ops:  17
compiled vars:  !0 = $exception
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_METHOD_CALL                                         !0, 'getTrace'
          2        DO_FCALL                                      0  $2      
          3        FETCH_DIM_R                                      ~3      $2, 0
          4        FETCH_DIM_R                                      ~4      ~3, 'file'
          5        ASSIGN_OBJ                                               !0, 'file'
          6        OP_DATA                                                  ~4
    5     7        INIT_METHOD_CALL                                         !0, 'getTrace'
          8        DO_FCALL                                      0  $6      
          9        FETCH_DIM_R                                      ~7      $6, 0
         10        FETCH_DIM_R                                      ~8      ~7, 'line'
         11        ASSIGN_OBJ                                               !0, 'line'
         12        OP_DATA                                                  ~8
    6    13        VERIFY_RETURN_TYPE                                       !0
         14      > RETURN                                                   !0
    7    15*       VERIFY_RETURN_TYPE                                       
         16*     > RETURN                                                   null

End of function throw

End of class ExceptionFixer.

Class MyException:
Function create:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HlZDW
function name:  create
number of ops:  11
compiled vars:  !0 = $self
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   NEW                                              $1      'MyException'
          1        SEND_VAL_EX                                              'Custom+exception'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   13     4        INIT_STATIC_METHOD_CALL                                  'throw'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0  $4      
          7        VERIFY_RETURN_TYPE                                       $4
          8      > RETURN                                                   $4
   14     9*       VERIFY_RETURN_TYPE                                       
         10*     > RETURN                                                   null

End of function create

End of class MyException.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.49 ms | 1399 KiB | 13 Q