3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Exception { protected $message = 'Unknown exception'; // exception message private $string; // __toString cache protected $code = 0; // user defined exception code protected $file; // source filename of exception protected $line; // source line of exception private $trace; // backtrace private $previous; // previous exception if nested exception public function __construct($message, $code = 0) { // some code // make sure everything is assigned properly self::__construct($message, $code); } } // Inhibits cloning of exceptions. /** * NewException * Extends the Exception class so that the $message parameter is now mendatory. * */ class NewException extends Exception { //$message is now not optional, just for the extension. public function __construct($message, $code = 0, Exception $previous = null) { parent::__construct($message, $code, $previous); } } /** * TestException * Tests and throws Exceptions. */ class TestException { const NONE = 0; const NORMAL = 1; const CUSTOM = 2; public function __construct($type = self::NONE) { switch ($type) { case 1: throw new Exception('Normal Exception'); break; case 2: throw new NewException('Custom Exception'); break; default: return 0; //No exception is thrown. } } } try { $t = new TestException(TestException::CUSTOM); } catch (Exception $e) { print_r($e); //Exception Caught } ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 6
Branch analysis from position: 6
2 jumps found. (Code = 107) Position 1 = 7, Position 2 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MXVgu
function name:  (null)
number of ops:  11
compiled vars:  !0 = $t, !1 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   DECLARE_CLASS                                            'exception'
   56     1        NEW                                              $2      'TestException'
          2        SEND_VAL_EX                                              2
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $2
          5      > JMP                                                      ->10
   58     6  E > > CATCH                                       last         'Exception'
   59     7    >   INIT_FCALL                                               'print_r'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                                 
   62    10    > > RETURN                                                   1

Class Exception:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MXVgu
function name:  __construct
number of ops:  7
compiled vars:  !0 = $message, !1 = $code
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
   15     2        INIT_STATIC_METHOD_CALL                                  
          3        SEND_VAR_EX                                              !0
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0          
   16     6      > RETURN                                                   null

End of function __construct

End of class Exception.

Class NewException:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MXVgu
function name:  __construct
number of ops:  9
compiled vars:  !0 = $message, !1 = $code, !2 = $previous
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
          2        RECV_INIT                                        !2      null
   29     3        INIT_STATIC_METHOD_CALL                                  
          4        SEND_VAR_EX                                              !0
          5        SEND_VAR_EX                                              !1
          6        SEND_VAR_EX                                              !2
          7        DO_FCALL                                      0          
   30     8      > RETURN                                                   null

End of function __construct

End of class NewException.

Class TestException:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/MXVgu
function name:  __construct
number of ops:  18
compiled vars:  !0 = $type
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV_INIT                                        !0      <const ast>
   43     1        IS_EQUAL                                                 !0, 1
          2      > JMPNZ                                                    ~1, ->6
   46     3    >   IS_EQUAL                                                 !0, 2
          4      > JMPNZ                                                    ~1, ->11
          5    > > JMP                                                      ->16
   44     6    >   NEW                                              $2      'Exception'
          7        SEND_VAL_EX                                              'Normal+Exception'
          8        DO_FCALL                                      0          
          9      > THROW                                         0          $2
   45    10*       JMP                                                      ->17
   47    11    >   NEW                                              $4      'NewException'
         12        SEND_VAL_EX                                              'Custom+Exception'
         13        DO_FCALL                                      0          
         14      > THROW                                         0          $4
   48    15*       JMP                                                      ->17
   50    16    > > RETURN                                                   0
   52    17*     > RETURN                                                   null

End of function __construct

End of class TestException.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.13 ms | 1400 KiB | 15 Q