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 function __construct($message = null, $code = 0 ) { // make sure everything is assigned properly self::__construct($message, $code); } // Overrideable; } // Overrideable class MyException extends Exception{ public function __construct($message, $code = 0, Exception $previous = null) { // some code // make sure everything is assigned properly parent::__construct($message, $code, $previous); } // custom string representation of object public function __toString() { return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; } public function customFunction() { echo "A custom function for this type of exception\n"; } } class TestException { public $var; const THROW_NONE = 0; const THROW_CUSTOM = 1; const THROW_DEFAULT = 2; function __construct($avalue = self::THROW_NONE) { switch ($avalue) { case self::THROW_CUSTOM: // throw custom exception throw new MyException('1 is an invalid parameter', 5); break; case self::THROW_DEFAULT: // throw default one. throw new Exception('2 is not allowed as a parameter', 6); break; default: // No exception, object will be created. $this->var = $avalue; break; } } } try { $o = new TestException(TestException::THROW_CUSTOM); } catch (MyException $e) { // Will be caught echo "Caught my exception\n", $e; $e->customFunction(); } catch (Exception $e) { // Skipped echo "Caught Default Exception\n", $e; } // Continue execution var_dump($o); // Null echo "\n\n"; // Example 2 try { $o = new TestException(TestException::THROW_DEFAULT); } catch (MyException $e) { // Doesn't match this type echo "Caught my exception\n", $e; $e->customFunction(); } catch (Exception $e) { // Will be caught echo "Caught Default Exception\n", $e; } // Continue execution var_dump($o); // Null echo "\n\n"; try { $o = new TestException(TestException::THROW_CUSTOM); } catch (Exception $e) { // Will be caught echo "Default Exception caught\n", $e; } // Continue execution var_dump($o); // Null echo "\n\n"; try { $o = new TestException(); } catch (Exception $e) { // Skipped, no exception echo "Default Exception caught\n", $e; } // Continue execution var_dump($o); // TestException echo "p\n\n"; ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 7
Branch analysis from position: 7
2 jumps found. (Code = 107) Position 1 = 8, Position 2 = 13
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 13
2 jumps found. (Code = 107) Position 1 = 14, Position 2 = -2
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
Found catch point at position: 13
Branch analysis from position: 13
Found catch point at position: 25
Branch analysis from position: 25
2 jumps found. (Code = 107) Position 1 = 26, Position 2 = 31
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
Branch analysis from position: 31
2 jumps found. (Code = 107) Position 1 = 32, Position 2 = -2
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
Found catch point at position: 31
Branch analysis from position: 31
Found catch point at position: 43
Branch analysis from position: 43
2 jumps found. (Code = 107) Position 1 = 44, Position 2 = -2
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
Found catch point at position: 54
Branch analysis from position: 54
2 jumps found. (Code = 107) Position 1 = 55, Position 2 = -2
Branch analysis from position: 55
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sMNZH
function name:  (null)
number of ops:  62
compiled vars:  !0 = $o, !1 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   DECLARE_CLASS                                            'exception'
   22     1        DECLARE_CLASS                                            'myexception', 'exception'
   68     2        NEW                                              $2      'TestException'
          3        SEND_VAL_EX                                              1
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $2
          6      > JMP                                                      ->16
   69     7  E > > CATCH                                                    'MyException', ->13
   70     8    >   ECHO                                                     'Caught+my+exception%0A'
          9        ECHO                                                     !1
   71    10        INIT_METHOD_CALL                                         !1, 'customFunction'
         11        DO_FCALL                                      0          
         12      > JMP                                                      ->16
   72    13  E > > CATCH                                       last         'Exception'
   73    14    >   ECHO                                                     'Caught+Default+Exception%0A'
         15        ECHO                                                     !1
   77    16    >   INIT_FCALL                                               'var_dump'
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                                 
   78    19        ECHO                                                     '%0A%0A'
   83    20        NEW                                              $7      'TestException'
         21        SEND_VAL_EX                                              2
         22        DO_FCALL                                      0          
         23        ASSIGN                                                   !0, $7
         24      > JMP                                                      ->34
   84    25  E > > CATCH                                                    'MyException', ->31
   85    26    >   ECHO                                                     'Caught+my+exception%0A'
         27        ECHO                                                     !1
   86    28        INIT_METHOD_CALL                                         !1, 'customFunction'
         29        DO_FCALL                                      0          
         30      > JMP                                                      ->34
   87    31  E > > CATCH                                       last         'Exception'
   88    32    >   ECHO                                                     'Caught+Default+Exception%0A'
         33        ECHO                                                     !1
   92    34    >   INIT_FCALL                                               'var_dump'
         35        SEND_VAR                                                 !0
         36        DO_ICALL                                                 
   93    37        ECHO                                                     '%0A%0A'
   95    38        NEW                                              $12     'TestException'
         39        SEND_VAL_EX                                              1
         40        DO_FCALL                                      0          
         41        ASSIGN                                                   !0, $12
         42      > JMP                                                      ->46
   96    43  E > > CATCH                                       last         'Exception'
   97    44    >   ECHO                                                     'Default+Exception+caught%0A'
         45        ECHO                                                     !1
  101    46    >   INIT_FCALL                                               'var_dump'
         47        SEND_VAR                                                 !0
         48        DO_ICALL                                                 
  102    49        ECHO                                                     '%0A%0A'
  104    50        NEW                                              $16     'TestException'
         51        DO_FCALL                                      0          
         52        ASSIGN                                                   !0, $16
         53      > JMP                                                      ->57
  105    54  E > > CATCH                                       last         'Exception'
  106    55    >   ECHO                                                     'Default+Exception+caught%0A'
         56        ECHO                                                     !1
  110    57    >   INIT_FCALL                                               'var_dump'
         58        SEND_VAR                                                 !0
         59        DO_ICALL                                                 
  111    60        ECHO                                                     'p%0A%0A'
  112    61      > RETURN                                                   1

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

End of function __construct

Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sMNZH
function name:  __toString
number of ops:  12
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   ROPE_INIT                                     5  ~3      '%3A+%5B'
          1        FETCH_OBJ_R                                      ~0      'code'
          2        ROPE_ADD                                      1  ~3      ~3, ~0
          3        ROPE_ADD                                      2  ~3      ~3, '%5D%3A+'
          4        FETCH_OBJ_R                                      ~1      'message'
          5        ROPE_ADD                                      3  ~3      ~3, ~1
          6        ROPE_END                                      4  ~2      ~3, '%0A'
          7        CONCAT                                           ~6      'MyException', ~2
          8        VERIFY_RETURN_TYPE                                       ~6
          9      > RETURN                                                   ~6
   33    10*       VERIFY_RETURN_TYPE                                       
         11*     > RETURN                                                   null

End of function __tostring

Function customfunction:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sMNZH
function name:  customFunction
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   ECHO                                                     'A+custom+function+for+this+type+of+exception%0A'
   37     1      > RETURN                                                   null

End of function customfunction

End of class MyException.

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 = 12
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/sMNZH
function name:  __construct
number of ops:  22
compiled vars:  !0 = $avalue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV_INIT                                        !0      <const ast>
   49     1        IS_EQUAL                                                 !0, 1
          2      > JMPNZ                                                    ~1, ->6
          3    >   IS_EQUAL                                                 !0, 2
          4      > JMPNZ                                                    ~1, ->12
          5    > > JMP                                                      ->18
   52     6    >   NEW                                              $2      'MyException'
          7        SEND_VAL_EX                                              '1+is+an+invalid+parameter'
          8        SEND_VAL_EX                                              5
          9        DO_FCALL                                      0          
         10      > THROW                                         0          $2
   53    11*       JMP                                                      ->21
   57    12    >   NEW                                              $4      'Exception'
         13        SEND_VAL_EX                                              '2+is+not+allowed+as+a+parameter'
         14        SEND_VAL_EX                                              6
         15        DO_FCALL                                      0          
         16      > THROW                                         0          $4
   58    17*       JMP                                                      ->21
   62    18    >   ASSIGN_OBJ                                               'var'
         19        OP_DATA                                                  !0
   63    20      > JMP                                                      ->21
   65    21    > > RETURN                                                   null

End of function __construct

End of class TestException.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.65 ms | 1408 KiB | 15 Q