3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Parser { private $chunkSize; private $buffer = ''; private $callback; public function __construct($chunkSize) { $this->chunkSize = $chunkSize; } public function onChunk($callback) { $this->callback = $callback; } public function parse($data) { $this->buffer .= $data; while (strlen($data) >= $this->chunkSize) { $chunk = (string)substr($this->buffer, 0, $this->chunkSize); $this->buffer = (string)substr($this->buffer, $this->chunkSize); call_user_func($this->callback, $chunk); } } } $p = new Parser(43); $p->onChunk(function($data) { echo "Got chunk of data: {$data}\n"; }); $p->parse('The quick brown fox jumps over the lazy dogThe quick brown fox'); $p->parse(' jum'); $p->parse('ps'); $p->parse(' over the lazy dogThe quick brown fox jumps '); $p->parse('over the lazy dog');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/M5ekp
function name:  (null)
number of ops:  24
compiled vars:  !0 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   NEW                                              $1      'Parser'
          1        SEND_VAL_EX                                              43
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   35     4        INIT_METHOD_CALL                                         !0, 'onChunk'
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FM5ekp%3A35%240'
   37     6        SEND_VAL_EX                                              ~4
          7        DO_FCALL                                      0          
   39     8        INIT_METHOD_CALL                                         !0, 'parse'
          9        SEND_VAL_EX                                              'The+quick+brown+fox+jumps+over+the+lazy+dogThe+quick+brown+fox'
         10        DO_FCALL                                      0          
   40    11        INIT_METHOD_CALL                                         !0, 'parse'
         12        SEND_VAL_EX                                              '+jum'
         13        DO_FCALL                                      0          
   41    14        INIT_METHOD_CALL                                         !0, 'parse'
         15        SEND_VAL_EX                                              'ps'
         16        DO_FCALL                                      0          
   42    17        INIT_METHOD_CALL                                         !0, 'parse'
         18        SEND_VAL_EX                                              '+over+the+lazy+dogThe+quick+brown+fox+jumps+'
         19        DO_FCALL                                      0          
   43    20        INIT_METHOD_CALL                                         !0, 'parse'
         21        SEND_VAL_EX                                              'over+the+lazy+dog'
         22        DO_FCALL                                      0          
         23      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FM5ekp%3A35%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/M5ekp
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   36     1        ROPE_INIT                                     3  ~2      'Got+chunk+of+data%3A+'
          2        ROPE_ADD                                      1  ~2      ~2, !0
          3        ROPE_END                                      2  ~1      ~2, '%0A'
          4        ECHO                                                     ~1
   37     5      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FM5ekp%3A35%240

Class Parser:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/M5ekp
function name:  __construct
number of ops:  4
compiled vars:  !0 = $chunkSize
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   13     1        ASSIGN_OBJ                                               'chunkSize'
          2        OP_DATA                                                  !0
   14     3      > RETURN                                                   null

End of function __construct

Function onchunk:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/M5ekp
function name:  onChunk
number of ops:  4
compiled vars:  !0 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   18     1        ASSIGN_OBJ                                               'callback'
          2        OP_DATA                                                  !0
   19     3      > RETURN                                                   null

End of function onchunk

Function parse:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 4
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 4
Branch analysis from position: 30
Branch analysis from position: 4
filename:       /in/M5ekp
function name:  parse
number of ops:  31
compiled vars:  !0 = $data, !1 = $chunk
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   23     1        ASSIGN_OBJ_OP                                 8          'buffer'
          2        OP_DATA                                                  !0
   25     3      > JMP                                                      ->26
   26     4    >   INIT_FCALL                                               'substr'
          5        FETCH_OBJ_R                                      ~3      'buffer'
          6        SEND_VAL                                                 ~3
          7        SEND_VAL                                                 0
          8        FETCH_OBJ_R                                      ~4      'chunkSize'
          9        SEND_VAL                                                 ~4
         10        DO_ICALL                                         $5      
         11        CAST                                          6  ~6      $5
         12        ASSIGN                                                   !1, ~6
   27    13        INIT_FCALL                                               'substr'
         14        FETCH_OBJ_R                                      ~9      'buffer'
         15        SEND_VAL                                                 ~9
         16        FETCH_OBJ_R                                      ~10     'chunkSize'
         17        SEND_VAL                                                 ~10
         18        DO_ICALL                                         $11     
         19        CAST                                          6  ~12     $11
         20        ASSIGN_OBJ                                               'buffer'
         21        OP_DATA                                                  ~12
   29    22        FETCH_OBJ_R                                      ~13     'callback'
         23        INIT_USER_CALL                                1          'call_user_func', ~13
         24        SEND_USER                                                !1
         25        DO_FCALL                                      0          
   25    26    >   STRLEN                                           ~15     !0
         27        FETCH_OBJ_R                                      ~16     'chunkSize'
         28        IS_SMALLER_OR_EQUAL                                      ~16, ~15
         29      > JMPNZ                                                    ~17, ->4
   31    30    > > RETURN                                                   null

End of function parse

End of class Parser.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.02 ms | 1396 KiB | 15 Q