3v4l.org

run code in 500+ PHP versions simultaneously
<?php // based on Alexandre Daubois code // Refactored to make it running here class MockHttp { private string $data = ''; private int $pos = 0; public $context; public function stream_open( string $path, string $mode, int $options, ?string &$opened_path = null ): bool { $this->data = json_encode([ 'mocked' => true, 'url' => $path, ]); $this->pos = 0; return true; } public function stream_read(int $count): string { $result = substr($this->data, $this->pos, $count); $this->pos += strlen($result); return $result; } public function stream_eof(): bool { return $this->pos >= strlen($this->data); } public function stream_stat(): array { return [ 'size' => strlen($this->data), ]; } // Required when using STREAM_IS_URL in modern PHP versions public function url_stat(string $path, int $flags): array|false { return [ 'size' => strlen($this->data), ]; } } stream_wrapper_unregister('http'); stream_wrapper_register('http', MockHttp::class, STREAM_IS_URL); $data = file_get_contents('http://api.example.com/users'); var_dump($data); stream_wrapper_restore('http');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RH2uq
function name:  (null)
number of ops:  19
compiled vars:  !0 = $data
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   57     0  E >   INIT_FCALL                                                   'stream_wrapper_unregister'
          1        SEND_VAL                                                     'http'
          2        DO_ICALL                                                     
   58     3        INIT_FCALL                                                   'stream_wrapper_register'
          4        SEND_VAL                                                     'http'
          5        SEND_VAL                                                     'MockHttp'
          6        SEND_VAL                                                     1
          7        DO_ICALL                                                     
   60     8        INIT_FCALL                                                   'file_get_contents'
          9        SEND_VAL                                                     'http%3A%2F%2Fapi.example.com%2Fusers'
         10        DO_ICALL                                             $3      
         11        ASSIGN                                                       !0, $3
   62    12        INIT_FCALL                                                   'var_dump'
         13        SEND_VAR                                                     !0
         14        DO_ICALL                                                     
   64    15        INIT_FCALL                                                   'stream_wrapper_restore'
         16        SEND_VAL                                                     'http'
         17        DO_ICALL                                                     
         18      > RETURN                                                       1

Class MockHttp:
Function stream_open:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RH2uq
function name:  stream_open
number of ops:  16
compiled vars:  !0 = $path, !1 = $mode, !2 = $options, !3 = $opened_path
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   13     0  E >   RECV                                                 !0      
   14     1        RECV                                                 !1      
   15     2        RECV                                                 !2      
   16     3        RECV_INIT                                            !3      null
   18     4        INIT_FCALL                                                   'json_encode'
   19     5        INIT_ARRAY                                           ~5      <true>, 'mocked'
   20     6        ADD_ARRAY_ELEMENT                                    ~5      !0, 'url'
          7        SEND_VAL                                                     ~5
   18     8        DO_ICALL                                             $6      
          9        ASSIGN_OBJ                                                   'data'
   20    10        OP_DATA                                                      $6
   23    11        ASSIGN_OBJ                                                   'pos'
         12        OP_DATA                                                      0
   25    13      > RETURN                                                       <true>
   26    14*       VERIFY_RETURN_TYPE                                           
         15*     > RETURN                                                       null

End of function stream_open

Function stream_read:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RH2uq
function name:  stream_read
number of ops:  13
compiled vars:  !0 = $count, !1 = $result
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   28     0  E >   RECV                                                 !0      
   30     1        FETCH_OBJ_R                                          ~2      'data'
          2        FETCH_OBJ_R                                          ~3      'pos'
          3        FRAMELESS_ICALL_3                substr              ~4      ~2, ~3
          4        OP_DATA                                                      !0
          5        ASSIGN                                                       !1, ~4
   31     6        STRLEN                                               ~7      !1
          7        ASSIGN_OBJ_OP                                     1          'pos'
          8        OP_DATA                                                      ~7
   33     9        VERIFY_RETURN_TYPE                                           !1
         10      > RETURN                                                       !1
   34    11*       VERIFY_RETURN_TYPE                                           
         12*     > 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/RH2uq
function name:  stream_eof
number of ops:  8
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   38     0  E >   FETCH_OBJ_R                                          ~0      'pos'
          1        FETCH_OBJ_R                                          ~1      'data'
          2        STRLEN                                               ~2      ~1
          3        IS_SMALLER_OR_EQUAL                                  ~3      ~2, ~0
          4        VERIFY_RETURN_TYPE                                           ~3
          5      > RETURN                                                       ~3
   39     6*       VERIFY_RETURN_TYPE                                           
          7*     > RETURN                                                       null

End of function stream_eof

Function stream_stat:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RH2uq
function name:  stream_stat
number of ops:  7
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   44     0  E >   FETCH_OBJ_R                                          ~0      'data'
          1        STRLEN                                               ~1      ~0
          2        INIT_ARRAY                                           ~2      ~1, 'size'
          3        VERIFY_RETURN_TYPE                                           ~2
          4      > RETURN                                                       ~2
   46     5*       VERIFY_RETURN_TYPE                                           
          6*     > RETURN                                                       null

End of function stream_stat

Function url_stat:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RH2uq
function name:  url_stat
number of ops:  9
compiled vars:  !0 = $path, !1 = $flags
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   49     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   52     2        FETCH_OBJ_R                                          ~2      'data'
          3        STRLEN                                               ~3      ~2
          4        INIT_ARRAY                                           ~4      ~3, 'size'
          5        VERIFY_RETURN_TYPE                                           ~4
          6      > RETURN                                                       ~4
   54     7*       VERIFY_RETURN_TYPE                                           
          8*     > RETURN                                                       null

End of function url_stat

End of class MockHttp.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
139.78 ms | 3397 KiB | 19 Q