3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Rixxi\Utils; class Batch implements \ArrayAccess { /** @var int */ private $limit; /** @var int */ private $counter = 0; /** @var callable */ private $onFlush; /** @var array */ private $values = array(); /** * Callback will receive all appended values as an array. When limit is reached flush is triggered. * * @param callable * @param int */ public function __construct(callable $onFlush, $limit = 1000) { $this->onFlush = $onFlush; $this->limit = $limit; } public function __destruct() { $this->flush(); } /** * Adds value to batch. If limit is reached flush is triggered immediately. * * @param mixed */ public function append($value) { $this->values[] = $value; if (++$this->counter === $this->limit) { $this->flush(); } } /** * If at least one value was appended, calls callback and resets state. */ public function flush() { if ($this->counter !== 0) { $onFlush = $this->onFlush; // performance optimization $onFlush($this->values); $this->values = array(); $this->counter = 0; } } public function offsetExists($index) { throw new NotSupportedException('Checking existence of index is not supported use callback instead.'); } public function offsetGet($index) { throw new NotSupportedException('Retrieving values via index is not supported use callback instead.'); } public function offsetSet($index, $value) { if ($index !== NULL) { throw new InvalidArgumentException('Setting values via index is not supported use append instead.'); } $this->append($value); } public function offsetUnset($index) { throw new NotSupportedException('Batch is append only.'); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cV6EX
function name:  (null)
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   DECLARE_CLASS                                            'rixxi%5Cutils%5Cbatch'
   96     1      > RETURN                                                   1

Class Rixxi\Utils\Batch:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cV6EX
function name:  __construct
number of ops:  7
compiled vars:  !0 = $onFlush, !1 = $limit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      1000
   30     2        ASSIGN_OBJ                                               'onFlush'
          3        OP_DATA                                                  !0
   31     4        ASSIGN_OBJ                                               'limit'
          5        OP_DATA                                                  !1
   32     6      > RETURN                                                   null

End of function __construct

Function __destruct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cV6EX
function name:  __destruct
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   INIT_METHOD_CALL                                         'flush'
          1        DO_FCALL                                      0          
   38     2      > RETURN                                                   null

End of function __destruct

Function append:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/cV6EX
function name:  append
number of ops:  11
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
   48     1        FETCH_OBJ_W                                      $1      'values'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
   49     4        PRE_INC_OBJ                                      ~3      'counter'
          5        FETCH_OBJ_R                                      ~4      'limit'
          6        IS_IDENTICAL                                             ~3, ~4
          7      > JMPZ                                                     ~5, ->10
   50     8    >   INIT_METHOD_CALL                                         'flush'
          9        DO_FCALL                                      0          
   52    10    > > RETURN                                                   null

End of function append

Function flush:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 14
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/cV6EX
function name:  flush
number of ops:  15
compiled vars:  !0 = $onFlush
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   FETCH_OBJ_R                                      ~1      'counter'
          1        IS_NOT_IDENTICAL                                         ~1, 0
          2      > JMPZ                                                     ~2, ->14
   61     3    >   FETCH_OBJ_R                                      ~3      'onFlush'
          4        ASSIGN                                                   !0, ~3
   62     5        INIT_DYNAMIC_CALL                                        !0
          6        CHECK_FUNC_ARG                                           
          7        FETCH_OBJ_FUNC_ARG                               $5      'values'
          8        SEND_FUNC_ARG                                            $5
          9        DO_FCALL                                      0          
   63    10        ASSIGN_OBJ                                               'values'
         11        OP_DATA                                                  <array>
   64    12        ASSIGN_OBJ                                               'counter'
         13        OP_DATA                                                  0
   66    14    > > RETURN                                                   null

End of function flush

Function offsetexists:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/cV6EX
function name:  offsetExists
number of ops:  6
compiled vars:  !0 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   RECV                                             !0      
   71     1        NEW                                              $1      'Rixxi%5CUtils%5CNotSupportedException'
          2        SEND_VAL_EX                                              'Checking+existence+of+index+is+not+supported+use+callback+instead.'
          3        DO_FCALL                                      0          
          4      > THROW                                         0          $1
   72     5*     > RETURN                                                   null

End of function offsetexists

Function offsetget:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/cV6EX
function name:  offsetGet
number of ops:  6
compiled vars:  !0 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   75     0  E >   RECV                                             !0      
   77     1        NEW                                              $1      'Rixxi%5CUtils%5CNotSupportedException'
          2        SEND_VAL_EX                                              'Retrieving+values+via+index+is+not+supported+use+callback+instead.'
          3        DO_FCALL                                      0          
          4      > THROW                                         0          $1
   78     5*     > RETURN                                                   null

End of function offsetget

Function offsetset:
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/cV6EX
function name:  offsetSet
number of ops:  12
compiled vars:  !0 = $index, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   81     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   83     2        TYPE_CHECK                                  1020          !0
          3      > JMPZ                                                     ~2, ->8
   84     4    >   NEW                                              $3      'Rixxi%5CUtils%5CInvalidArgumentException'
          5        SEND_VAL_EX                                              'Setting+values+via+index+is+not+supported+use+append+instead.'
          6        DO_FCALL                                      0          
          7      > THROW                                         0          $3
   87     8    >   INIT_METHOD_CALL                                         'append'
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0          
   88    11      > RETURN                                                   null

End of function offsetset

Function offsetunset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/cV6EX
function name:  offsetUnset
number of ops:  6
compiled vars:  !0 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   91     0  E >   RECV                                             !0      
   93     1        NEW                                              $1      'Rixxi%5CUtils%5CNotSupportedException'
          2        SEND_VAL_EX                                              'Batch+is+append+only.'
          3        DO_FCALL                                      0          
          4      > THROW                                         0          $1
   94     5*     > RETURN                                                   null

End of function offsetunset

End of class Rixxi\Utils\Batch.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.1 ms | 1407 KiB | 13 Q