3v4l.org

run code in 300+ PHP versions simultaneously
<?php $txt = <<<TXT 1 Hello! 2 How 3 are 4 you? TXT; class FileObject extends SplFileObject { public function seek($offset) { if ($offset < 0) { throw new Exception("Can't seek file: " . $this->getPathname() . " to negative offset: $offset"); } $this->rewind(); for ($i = 0; $i < $offset; $i++) { $this->current(); $this->next(); if ($this->eof()) { break; } } $this->current(); } } $file = new FileObject('php://memory', 'w+'); $file->fwrite($txt); echo 'Seeking line 1...', PHP_EOL; $file->seek(0); echo 'Position in the file: ', $file->ftell(), PHP_EOL; echo 'Rest of the file: ', PHP_EOL, $file->fread(5000); echo PHP_EOL, '-------------', PHP_EOL; echo 'Seeking line 2...', PHP_EOL; $file->seek(1); echo 'Position in the file: ', $file->ftell(), PHP_EOL; echo 'Rest of the file: ', PHP_EOL, $file->fread(5000);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XUPgl
function name:  (null)
number of ops:  45
compiled vars:  !0 = $txt, !1 = $file
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '1+Hello%21%0A2+How%0A3+are%0A4+you%3F'
   31     1        NEW                                              $3      'FileObject'
          2        SEND_VAL_EX                                              'php%3A%2F%2Fmemory'
          3        SEND_VAL_EX                                              'w%2B'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $3
   32     6        INIT_METHOD_CALL                                         !1, 'fwrite'
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0          
   34     9        ECHO                                                     'Seeking+line+1...'
         10        ECHO                                                     '%0A'
   35    11        INIT_METHOD_CALL                                         !1, 'seek'
         12        SEND_VAL_EX                                              0
         13        DO_FCALL                                      0          
   36    14        ECHO                                                     'Position+in+the+file%3A+'
         15        INIT_METHOD_CALL                                         !1, 'ftell'
         16        DO_FCALL                                      0  $8      
         17        ECHO                                                     $8
         18        ECHO                                                     '%0A'
   37    19        ECHO                                                     'Rest+of+the+file%3A+'
         20        ECHO                                                     '%0A'
         21        INIT_METHOD_CALL                                         !1, 'fread'
         22        SEND_VAL_EX                                              5000
         23        DO_FCALL                                      0  $9      
         24        ECHO                                                     $9
   39    25        ECHO                                                     '%0A'
         26        ECHO                                                     '-------------'
         27        ECHO                                                     '%0A'
   41    28        ECHO                                                     'Seeking+line+2...'
         29        ECHO                                                     '%0A'
   42    30        INIT_METHOD_CALL                                         !1, 'seek'
         31        SEND_VAL_EX                                              1
         32        DO_FCALL                                      0          
   43    33        ECHO                                                     'Position+in+the+file%3A+'
         34        INIT_METHOD_CALL                                         !1, 'ftell'
         35        DO_FCALL                                      0  $11     
         36        ECHO                                                     $11
         37        ECHO                                                     '%0A'
   44    38        ECHO                                                     'Rest+of+the+file%3A+'
         39        ECHO                                                     '%0A'
         40        INIT_METHOD_CALL                                         !1, 'fread'
         41        SEND_VAL_EX                                              5000
         42        DO_FCALL                                      0  $12     
         43        ECHO                                                     $12
         44      > RETURN                                                   1

Class FileObject:
Function seek:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 13
Branch analysis from position: 3
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 17
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 25
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 17
Branch analysis from position: 28
Branch analysis from position: 17
filename:       /in/XUPgl
function name:  seek
number of ops:  31
compiled vars:  !0 = $offset, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   14     1        IS_SMALLER                                               !0, 0
          2      > JMPZ                                                     ~2, ->13
   15     3    >   NEW                                              $3      'Exception'
          4        INIT_METHOD_CALL                                         'getPathname'
          5        DO_FCALL                                      0  $4      
          6        CONCAT                                           ~5      'Can%27t+seek+file%3A+', $4
          7        NOP                                                      
          8        FAST_CONCAT                                      ~6      '+to+negative+offset%3A+', !0
          9        CONCAT                                           ~7      ~5, ~6
         10        SEND_VAL_EX                                              ~7
         11        DO_FCALL                                      0          
         12      > THROW                                         0          $3
   18    13    >   INIT_METHOD_CALL                                         'rewind'
         14        DO_FCALL                                      0          
   19    15        ASSIGN                                                   !1, 0
         16      > JMP                                                      ->26
   20    17    >   INIT_METHOD_CALL                                         'current'
         18        DO_FCALL                                      0          
   21    19        INIT_METHOD_CALL                                         'next'
         20        DO_FCALL                                      0          
   22    21        INIT_METHOD_CALL                                         'eof'
         22        DO_FCALL                                      0  $13     
         23      > JMPZ                                                     $13, ->25
   23    24    > > JMP                                                      ->28
   19    25    >   PRE_INC                                                  !1
         26    >   IS_SMALLER                                               !1, !0
         27      > JMPNZ                                                    ~15, ->17
   27    28    >   INIT_METHOD_CALL                                         'current'
         29        DO_FCALL                                      0          
   28    30      > RETURN                                                   null

End of function seek

End of class FileObject.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
181.2 ms | 1399 KiB | 13 Q