3v4l.org

run code in 300+ PHP versions simultaneously
<?php class FooWrapper { protected $opened = false; protected $path = ""; public function stream_close() { if (!$this->opened) { throw new RuntimeException("Closing an unopened stream"); } $this->opened = false; } public function stream_open($path, $mode, $options, &$opened_path) { if ($this->opened) { throw new Exception("opened already"); } if ($path == "foo://foo") { throw new Exception("Foo"); } $this->opened = true; $this->path = $path; return true; } public function stream_read($count) { if ($this->path === "foo://something") { throw new LogicException("something"); } return str_repeat('f', $count); } public function stream_eof() { return false; } } stream_wrapper_register("foo", "FooWrapper"); try { $foo = fopen("foo://foo", "r"); } catch (Exception $e) { echo "Caught " . get_class($e) . "\n"; } try { $f = fopen("foo://bar", "r"); var_dump(fread($f, 10)); fclose($f); } catch (\Exception $e) { echo "Caught " . get_class($e) . "\n"; } try { $f = fopen("foo://something", "r"); var_dump(fread($f, 52)); fclose($f); } catch (\Exception $e) { echo "Caught " . get_class($e) . "\n"; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
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: 10
Branch analysis from position: 10
2 jumps found. (Code = 107) Position 1 = 11, Position 2 = -2
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Found catch point at position: 31
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 = 57
Branch analysis from position: 57
Found catch point at position: 52
Branch analysis from position: 52
2 jumps found. (Code = 107) Position 1 = 53, Position 2 = -2
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IQ1SQ
function name:  (null)
number of ops:  58
compiled vars:  !0 = $foo, !1 = $e, !2 = $f
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   INIT_FCALL                                               'stream_wrapper_register'
          1        SEND_VAL                                                 'foo'
          2        SEND_VAL                                                 'FooWrapper'
          3        DO_ICALL                                                 
   37     4        INIT_FCALL                                               'fopen'
          5        SEND_VAL                                                 'foo%3A%2F%2Ffoo'
          6        SEND_VAL                                                 'r'
          7        DO_ICALL                                         $4      
          8        ASSIGN                                                   !0, $4
          9      > JMP                                                      ->15
   38    10  E > > CATCH                                       last         'Exception'
   39    11    >   GET_CLASS                                        ~6      !1
         12        CONCAT                                           ~7      'Caught+', ~6
         13        CONCAT                                           ~8      ~7, '%0A'
         14        ECHO                                                     ~8
   43    15    >   INIT_FCALL                                               'fopen'
         16        SEND_VAL                                                 'foo%3A%2F%2Fbar'
         17        SEND_VAL                                                 'r'
         18        DO_ICALL                                         $9      
         19        ASSIGN                                                   !2, $9
   44    20        INIT_FCALL                                               'var_dump'
         21        INIT_FCALL                                               'fread'
         22        SEND_VAR                                                 !2
         23        SEND_VAL                                                 10
         24        DO_ICALL                                         $11     
         25        SEND_VAR                                                 $11
         26        DO_ICALL                                                 
   45    27        INIT_FCALL                                               'fclose'
         28        SEND_VAR                                                 !2
         29        DO_ICALL                                                 
         30      > JMP                                                      ->36
   46    31  E > > CATCH                                       last         'Exception'
   47    32    >   GET_CLASS                                        ~14     !1
         33        CONCAT                                           ~15     'Caught+', ~14
         34        CONCAT                                           ~16     ~15, '%0A'
         35        ECHO                                                     ~16
   51    36    >   INIT_FCALL                                               'fopen'
         37        SEND_VAL                                                 'foo%3A%2F%2Fsomething'
         38        SEND_VAL                                                 'r'
         39        DO_ICALL                                         $17     
         40        ASSIGN                                                   !2, $17
   52    41        INIT_FCALL                                               'var_dump'
         42        INIT_FCALL                                               'fread'
         43        SEND_VAR                                                 !2
         44        SEND_VAL                                                 52
         45        DO_ICALL                                         $19     
         46        SEND_VAR                                                 $19
         47        DO_ICALL                                                 
   53    48        INIT_FCALL                                               'fclose'
         49        SEND_VAR                                                 !2
         50        DO_ICALL                                                 
         51      > JMP                                                      ->57
   54    52  E > > CATCH                                       last         'Exception'
   55    53    >   GET_CLASS                                        ~22     !1
         54        CONCAT                                           ~23     'Caught+', ~22
         55        CONCAT                                           ~24     ~23, '%0A'
         56        ECHO                                                     ~24
   56    57    > > RETURN                                                   1

Class FooWrapper:
Function stream_close:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IQ1SQ
function name:  stream_close
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   FETCH_OBJ_R                                      ~0      'opened'
          1        BOOL_NOT                                         ~1      ~0
          2      > JMPZ                                                     ~1, ->7
    8     3    >   NEW                                              $2      'RuntimeException'
          4        SEND_VAL_EX                                              'Closing+an+unopened+stream'
          5        DO_FCALL                                      0          
          6      > THROW                                         0          $2
   10     7    >   ASSIGN_OBJ                                               'opened'
          8        OP_DATA                                                  <false>
   11     9      > RETURN                                                   null

End of function stream_close

Function stream_open:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IQ1SQ
function name:  stream_open
number of ops:  22
compiled vars:  !0 = $path, !1 = $mode, !2 = $options, !3 = $opened_path
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   13     4        FETCH_OBJ_R                                      ~4      'opened'
          5      > JMPZ                                                     ~4, ->10
   14     6    >   NEW                                              $5      'Exception'
          7        SEND_VAL_EX                                              'opened+already'
          8        DO_FCALL                                      0          
          9      > THROW                                         0          $5
   16    10    >   IS_EQUAL                                                 !0, 'foo%3A%2F%2Ffoo'
         11      > JMPZ                                                     ~7, ->16
   17    12    >   NEW                                              $8      'Exception'
         13        SEND_VAL_EX                                              'Foo'
         14        DO_FCALL                                      0          
         15      > THROW                                         0          $8
   19    16    >   ASSIGN_OBJ                                               'opened'
         17        OP_DATA                                                  <true>
   20    18        ASSIGN_OBJ                                               'path'
         19        OP_DATA                                                  !0
   21    20      > RETURN                                                   <true>
   22    21*     > RETURN                                                   null

End of function stream_open

Function stream_read:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IQ1SQ
function name:  stream_read
number of ops:  14
compiled vars:  !0 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   24     1        FETCH_OBJ_R                                      ~1      'path'
          2        IS_IDENTICAL                                             ~1, 'foo%3A%2F%2Fsomething'
          3      > JMPZ                                                     ~2, ->8
   25     4    >   NEW                                              $3      'LogicException'
          5        SEND_VAL_EX                                              'something'
          6        DO_FCALL                                      0          
          7      > THROW                                         0          $3
   27     8    >   INIT_FCALL                                               'str_repeat'
          9        SEND_VAL                                                 'f'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $5      
         12      > RETURN                                                   $5
   28    13*     > RETURN                                                   null

End of function stream_read

Function stream_eof:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IQ1SQ
function name:  stream_eof
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E > > RETURN                                                   <false>
   31     1*     > RETURN                                                   null

End of function stream_eof

End of class FooWrapper.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.84 ms | 1408 KiB | 25 Q