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) { var_dump($this->buffer); $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');

Abusive script

This script was stopped while abusing our resources

Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/b2hPX
function name:  (null)
number of ops:  24
compiled vars:  !0 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   NEW                                              $1      'Parser'
          1        SEND_VAL_EX                                              43
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   36     4        INIT_METHOD_CALL                                         !0, 'onChunk'
          5        DECLARE_LAMBDA_FUNCTION                          ~4      [0]
   38     6        SEND_VAL_EX                                              ~4
   36     7        DO_FCALL                                      0          
   40     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          
   41    11        INIT_METHOD_CALL                                         !0, 'parse'
         12        SEND_VAL_EX                                              '+jum'
         13        DO_FCALL                                      0          
   42    14        INIT_METHOD_CALL                                         !0, 'parse'
         15        SEND_VAL_EX                                              'ps'
         16        DO_FCALL                                      0          
   43    17        INIT_METHOD_CALL                                         !0, 'parse'
         18        SEND_VAL_EX                                              '+over+the+lazy+dogThe+quick+brown+fox+jumps+'
         19        DO_FCALL                                      0          
   44    20        INIT_METHOD_CALL                                         !0, 'parse'
         21        SEND_VAL_EX                                              'over+the+lazy+dog'
         22        DO_FCALL                                      0          
         23      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/b2hPX
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
   37     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
   38     5      > RETURN                                                   null

End of Dynamic Function 0

Class Parser:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/b2hPX
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/b2hPX
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 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 4
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 4
Branch analysis from position: 34
Branch analysis from position: 4
filename:       /in/b2hPX
function name:  parse
number of ops:  35
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                                                      ->30
   26     4    >   INIT_FCALL                                               'var_dump'
          5        FETCH_OBJ_R                                      ~3      'buffer'
          6        SEND_VAL                                                 ~3
          7        DO_ICALL                                                 
   27     8        INIT_FCALL                                               'substr'
          9        FETCH_OBJ_R                                      ~5      'buffer'
         10        SEND_VAL                                                 ~5
         11        SEND_VAL                                                 0
         12        FETCH_OBJ_R                                      ~6      'chunkSize'
         13        SEND_VAL                                                 ~6
         14        DO_ICALL                                         $7      
         15        CAST                                          6  ~8      $7
         16        ASSIGN                                                   !1, ~8
   28    17        INIT_FCALL                                               'substr'
         18        FETCH_OBJ_R                                      ~11     'buffer'
         19        SEND_VAL                                                 ~11
         20        FETCH_OBJ_R                                      ~12     'chunkSize'
         21        SEND_VAL                                                 ~12
         22        DO_ICALL                                         $13     
         23        CAST                                          6  ~14     $13
         24        ASSIGN_OBJ                                               'buffer'
         25        OP_DATA                                                  ~14
   30    26        FETCH_OBJ_R                                      ~15     'callback'
         27        INIT_USER_CALL                                1          'call_user_func', ~15
         28        SEND_USER                                                !1
         29        DO_FCALL                                      0          
   25    30    >   STRLEN                                           ~17     !0
         31        FETCH_OBJ_R                                      ~18     'chunkSize'
         32        IS_SMALLER_OR_EQUAL                                      ~18, ~17
         33      > JMPNZ                                                    ~19, ->4
   32    34    > > RETURN                                                   null

End of function parse

End of class Parser.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.47 ms | 1012 KiB | 15 Q