3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Behaves like a PHP array (unstructured) */ class Bag { private $_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)); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iEMtl
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E > > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FiEMtl%3A14%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/iEMtl
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $carry, !1 = $x, !2 = $fn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   15     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
   16     8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FiEMtl%3A14%240

Function %00%7Bclosure%7D%2Fin%2FiEMtl%3A20%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/iEMtl
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $carry, !1 = $x, !2 = $fn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   21     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
   22     8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FiEMtl%3A20%241

Class Bag:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iEMtl
function name:  __construct
number of ops:  4
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        ASSIGN_OBJ                                               'data'
          2        OP_DATA                                                  !0
   11     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/iEMtl
function name:  some
number of ops:  13
compiled vars:  !0 = $fn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   14     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%2FiEMtl%3A14%240'
   16     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
   17    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/iEMtl
function name:  every
number of ops:  13
compiled vars:  !0 = $fn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     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%2FiEMtl%3A20%241'
   22     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
   23    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/iEMtl
function name:  reduce
number of ops:  11
compiled vars:  !0 = $fn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   26     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
   27    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/iEMtl
function name:  map
number of ops:  11
compiled vars:  !0 = $fn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   30     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
   31    10*     > RETURN                                                   null

End of function map

End of class Bag.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.89 ms | 1404 KiB | 17 Q