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 $callback; /** @var array */ private $values = array(); /** * @param callable $callback * @param int $limit */ public function __construct(callable $callback, $limit = 1000) { $this->callback = $callback; $this->limit = $limit; } public function __destruct() { $this->flush(); } public function add($value) { $this->values[] = $value; if (++$this->counter === $this->limit) { $this->flush(); } } public function flush() { if ($this->counter !== 0) { $callback = $this->callback; $callback($this->values); $this->values = array(); $this->counter = 0; } } public function offsetSet($index, $value) { if ($index !== NULL) { throw new Exception(); } $this->add($value); } public function offsetGet($index) { throw new NotSupportedException('You can only append to batch.'); } public function offsetExists($index) { throw new NotSupportedException('You can only append to batch.'); } public function offsetUnset($index) { throw new NotSupportedException('You can only append to batch.'); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/62g86
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'
   86     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/62g86
function name:  __construct
number of ops:  7
compiled vars:  !0 = $callback, !1 = $limit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      1000
   28     2        ASSIGN_OBJ                                               'callback'
          3        OP_DATA                                                  !0
   29     4        ASSIGN_OBJ                                               'limit'
          5        OP_DATA                                                  !1
   30     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/62g86
function name:  __destruct
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   INIT_METHOD_CALL                                         'flush'
          1        DO_FCALL                                      0          
   36     2      > RETURN                                                   null

End of function __destruct

Function add:
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/62g86
function name:  add
number of ops:  11
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
   41     1        FETCH_OBJ_W                                      $1      'values'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
   42     4        PRE_INC_OBJ                                      ~3      'counter'
          5        FETCH_OBJ_R                                      ~4      'limit'
          6        IS_IDENTICAL                                             ~3, ~4
          7      > JMPZ                                                     ~5, ->10
   43     8    >   INIT_METHOD_CALL                                         'flush'
          9        DO_FCALL                                      0          
   45    10    > > RETURN                                                   null

End of function add

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/62g86
function name:  flush
number of ops:  15
compiled vars:  !0 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   FETCH_OBJ_R                                      ~1      'counter'
          1        IS_NOT_IDENTICAL                                         ~1, 0
          2      > JMPZ                                                     ~2, ->14
   51     3    >   FETCH_OBJ_R                                      ~3      'callback'
          4        ASSIGN                                                   !0, ~3
   52     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          
   53    10        ASSIGN_OBJ                                               'values'
         11        OP_DATA                                                  <array>
   54    12        ASSIGN_OBJ                                               'counter'
         13        OP_DATA                                                  0
   56    14    > > RETURN                                                   null

End of function flush

Function offsetset:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/62g86
function name:  offsetSet
number of ops:  11
compiled vars:  !0 = $index, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   61     2        TYPE_CHECK                                  1020          !0
          3      > JMPZ                                                     ~2, ->7
   62     4    >   NEW                                              $3      'Rixxi%5CUtils%5CException'
          5        DO_FCALL                                      0          
          6      > THROW                                         0          $3
   65     7    >   INIT_METHOD_CALL                                         'add'
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
   66    10      > RETURN                                                   null

End of function offsetset

Function offsetget:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/62g86
function name:  offsetGet
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                                              'You+can+only+append+to+batch.'
          3        DO_FCALL                                      0          
          4      > THROW                                         0          $1
   72     5*     > RETURN                                                   null

End of function offsetget

Function offsetexists:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/62g86
function name:  offsetExists
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                                              'You+can+only+append+to+batch.'
          3        DO_FCALL                                      0          
          4      > THROW                                         0          $1
   78     5*     > RETURN                                                   null

End of function offsetexists

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

End of function offsetunset

End of class Rixxi\Utils\Batch.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.08 ms | 1403 KiB | 13 Q