3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Behaves like a PHP array (unstructured) */ class Bag implements IteratorAggregate, ArrayAccess { private $__data; // Implementation for ArrayAccess public function offsetSet($offset, $value) { if (is_null($offset)) { $this->__data[] = value; } else { $this->__data[$offset] = $value; } } public function offsetExists($offset) { return isset($this->__data[$offset]); } public function offsetUnset($offset) { unset($this->__data[$offset]); } public function offsetGet($offset) { return isset($this->__data[$offset]) ? $this->__data[$offset] : null; } // Implementation for IteratorAggregate public function getIterator() { return new ArrayIterator($this->__data); } public function __construct(array $data) { $this->__data = $data; } public function some(Closure $fn) { return new Bag(array_reduce($this->__data, function ($carry, $x) { return $fn($x) || $carry; }, false)); } public function every(Closure $fn) { return new Bag(array_reduce($this->__data, function ($carry, $x) { return $fn($x) && $carry; }, true)); } public function reduce(Closure $fn) { return new Bag(array_reduce($this->__data, $fn)); } public function map(Closure $fn) { return new Bag(array_map($fn, $this->__data)); } public function filter(Closure $fn) { return new Bag(array_filter($this->__data, $fn)); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QcfvL
function name:  (null)
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   DECLARE_CLASS                                            'bag'
   69     1      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FQcfvL%3A47%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/QcfvL
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $carry, !1 = $x, !2 = $fn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   48     2        INIT_DYNAMIC_CALL                                        !2
          3        SEND_VAR_EX                                              !1
          4        DO_FCALL                                      0  $3      
          5      > JMPNZ_EX                                         ~4      $3, ->7
          6    >   BOOL                                             ~4      !0
          7    > > RETURN                                                   ~4
   49     8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FQcfvL%3A47%240

Function %00%7Bclosure%7D%2Fin%2FQcfvL%3A53%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/QcfvL
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $carry, !1 = $x, !2 = $fn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   54     2        INIT_DYNAMIC_CALL                                        !2
          3        SEND_VAR_EX                                              !1
          4        DO_FCALL                                      0  $3      
          5      > JMPZ_EX                                          ~4      $3, ->7
          6    >   BOOL                                             ~4      !0
          7    > > RETURN                                                   ~4
   55     8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FQcfvL%3A53%241

Class Bag:
Function offsetset:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QcfvL
function name:  offsetSet
number of ops:  13
compiled vars:  !0 = $offset, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   13     2        TYPE_CHECK                                    2          !0
          3      > JMPZ                                                     ~2, ->9
   14     4    >   FETCH_CONSTANT                                   ~5      'value'
          5        FETCH_OBJ_W                                      $3      '__data'
          6        ASSIGN_DIM                                               $3
          7        OP_DATA                                                  ~5
          8      > JMP                                                      ->12
   16     9    >   FETCH_OBJ_W                                      $6      '__data'
         10        ASSIGN_DIM                                               $6, !0
         11        OP_DATA                                                  !1
   18    12    > > RETURN                                                   null

End of function offsetset

Function offsetexists:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QcfvL
function name:  offsetExists
number of ops:  5
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   22     1        FETCH_OBJ_IS                                     ~1      '__data'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, !0
          3      > RETURN                                                   ~2
   23     4*     > RETURN                                                   null

End of function offsetexists

Function offsetunset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QcfvL
function name:  offsetUnset
number of ops:  4
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   27     1        FETCH_OBJ_UNSET                                  $1      '__data'
          2        UNSET_DIM                                                $1, !0
   28     3      > RETURN                                                   null

End of function offsetunset

Function offsetget:
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 = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QcfvL
function name:  offsetGet
number of ops:  11
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
   32     1        FETCH_OBJ_IS                                     ~1      '__data'
          2        ISSET_ISEMPTY_DIM_OBJ                         0          ~1, !0
          3      > JMPZ                                                     ~2, ->8
          4    >   FETCH_OBJ_R                                      ~3      '__data'
          5        FETCH_DIM_R                                      ~4      ~3, !0
          6        QM_ASSIGN                                        ~5      ~4
          7      > JMP                                                      ->9
          8    >   QM_ASSIGN                                        ~5      null
          9    > > RETURN                                                   ~5
   33    10*     > RETURN                                                   null

End of function offsetget

Function getiterator:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QcfvL
function name:  getIterator
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   NEW                                              $0      'ArrayIterator'
          1        CHECK_FUNC_ARG                                           
          2        FETCH_OBJ_FUNC_ARG                               $1      '__data'
          3        SEND_FUNC_ARG                                            $1
          4        DO_FCALL                                      0          
          5      > RETURN                                                   $0
   40     6*     > RETURN                                                   null

End of function getiterator

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

End of function __construct

Function some:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QcfvL
function name:  some
number of ops:  13
compiled vars:  !0 = $fn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
   47     1        NEW                                              $1      'Bag'
          2        INIT_FCALL                                               'array_reduce'
          3        FETCH_OBJ_R                                      ~2      '__data'
          4        SEND_VAL                                                 ~2
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FQcfvL%3A47%240'
   49     6        SEND_VAL                                                 ~3
          7        SEND_VAL                                                 <false>
          8        DO_ICALL                                         $4      
          9        SEND_VAR_NO_REF_EX                                       $4
         10        DO_FCALL                                      0          
         11      > RETURN                                                   $1
   50    12*     > RETURN                                                   null

End of function some

Function every:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QcfvL
function name:  every
number of ops:  13
compiled vars:  !0 = $fn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   RECV                                             !0      
   53     1        NEW                                              $1      'Bag'
          2        INIT_FCALL                                               'array_reduce'
          3        FETCH_OBJ_R                                      ~2      '__data'
          4        SEND_VAL                                                 ~2
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FQcfvL%3A53%241'
   55     6        SEND_VAL                                                 ~3
          7        SEND_VAL                                                 <true>
          8        DO_ICALL                                         $4      
          9        SEND_VAR_NO_REF_EX                                       $4
         10        DO_FCALL                                      0          
         11      > RETURN                                                   $1
   56    12*     > RETURN                                                   null

End of function every

Function reduce:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QcfvL
function name:  reduce
number of ops:  11
compiled vars:  !0 = $fn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   RECV                                             !0      
   59     1        NEW                                              $1      'Bag'
          2        INIT_FCALL                                               'array_reduce'
          3        FETCH_OBJ_R                                      ~2      '__data'
          4        SEND_VAL                                                 ~2
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $3      
          7        SEND_VAR_NO_REF_EX                                       $3
          8        DO_FCALL                                      0          
          9      > RETURN                                                   $1
   60    10*     > RETURN                                                   null

End of function reduce

Function map:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QcfvL
function name:  map
number of ops:  11
compiled vars:  !0 = $fn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   RECV                                             !0      
   63     1        NEW                                              $1      'Bag'
          2        INIT_FCALL                                               'array_map'
          3        SEND_VAR                                                 !0
          4        FETCH_OBJ_R                                      ~2      '__data'
          5        SEND_VAL                                                 ~2
          6        DO_ICALL                                         $3      
          7        SEND_VAR_NO_REF_EX                                       $3
          8        DO_FCALL                                      0          
          9      > RETURN                                                   $1
   64    10*     > RETURN                                                   null

End of function map

Function filter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QcfvL
function name:  filter
number of ops:  11
compiled vars:  !0 = $fn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   RECV                                             !0      
   67     1        NEW                                              $1      'Bag'
          2        INIT_FCALL                                               'array_filter'
          3        FETCH_OBJ_R                                      ~2      '__data'
          4        SEND_VAL                                                 ~2
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $3      
          7        SEND_VAR_NO_REF_EX                                       $3
          8        DO_FCALL                                      0          
          9      > RETURN                                                   $1
   68    10*     > RETURN                                                   null

End of function filter

End of class Bag.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.58 ms | 1412 KiB | 19 Q