3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types = 1); class Collection { private $_items; public function __construct(array $items = [])/*: void*/ { $this->_items = $items; } public function filter(callable $callback): self { foreach ($this->_items as $key => $value) if (!call_user_func($callback, $value)) unset($this->_items[$key]); return $this; } public function map(callable $callback): self { foreach ($this->_items as $key => $value) $this->_items[$key] = call_user_func($callback, $key, $value); return $this; } public function reindex(): self { $this->_items = array_values($this->_items); return $this; } public function sprintf(string $format): self { return $this->map(function ($key, $value) use ($format) { return substr_count($format, '%s') === 1 ? sprintf($format, $value) : sprintf($format, $key, $value); }); } public function keys(): self { $this->_items = array_keys($this->_items); return $this; } public function implode(string $delimiter = ''): string { $output = ''; $first = TRUE; foreach ($this->_items as $value) if ($first) { $output .= $value; $first = FALSE; } else $output .= "$delimiter$value"; return $output; } public static function index($index): callable { return function ($key, $value) use ($index) { return $value[$index]; }; } public static function property(string $property): callable { return function ($key, $value) use ($property) { return $value->$property; }; } public function values(): array { return $this->_items; } } class Filter { public static function not(callable $callback): callable { return function ($value) use ($callback) { return !call_user_func($callback, $value); }; } } echo (new Collection([ 42, 'one', 'two', ['foo' => 'BAR'], 'three', ['foo' => 'BAZ'], ])) ->filter(Filter::not('is_string')) ->filter('is_array') ->map(Collection::index('foo')) ->reindex() //->keys() //->sprintf('(%s,%s)') ->implode('_');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ncsGq
function name:  (null)
number of ops:  25
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   NEW                                              $0      'Collection'
   59     1        SEND_VAL_EX                                              <array>
          2        DO_FCALL                                      0          
   66     3        INIT_METHOD_CALL                                         $0, 'filter'
          4        INIT_STATIC_METHOD_CALL                                  'Filter', 'not'
          5        SEND_VAL                                                 'is_string'
          6        DO_FCALL                                      0  $2      
          7        SEND_VAR_NO_REF_EX                                       $2
          8        DO_FCALL                                      0  $3      
   67     9        INIT_METHOD_CALL                                         $3, 'filter'
         10        SEND_VAL_EX                                              'is_array'
         11        DO_FCALL                                      0  $4      
   68    12        INIT_METHOD_CALL                                         $4, 'map'
         13        INIT_STATIC_METHOD_CALL                                  'Collection', 'index'
         14        SEND_VAL                                                 'foo'
         15        DO_FCALL                                      0  $5      
         16        SEND_VAR_NO_REF_EX                                       $5
         17        DO_FCALL                                      0  $6      
   69    18        INIT_METHOD_CALL                                         $6, 'reindex'
         19        DO_FCALL                                      0  $7      
   72    20        INIT_METHOD_CALL                                         $7, 'implode'
         21        SEND_VAL_EX                                              '_'
         22        DO_FCALL                                      0  $8      
         23        ECHO                                                     $8
         24      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FncsGq%3A24%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ncsGq
function name:  {closure}
number of ops:  23
compiled vars:  !0 = $key, !1 = $value, !2 = $format
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   25     3        INIT_FCALL                                               'substr_count'
          4        SEND_VAR                                                 !2
          5        SEND_VAL                                                 '%25s'
          6        DO_ICALL                                         $3      
          7        IS_IDENTICAL                                             $3, 1
          8      > JMPZ                                                     ~4, ->15
          9    >   INIT_FCALL                                               'sprintf'
         10        SEND_VAR                                                 !2
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                         $5      
         13        QM_ASSIGN                                        ~6      $5
         14      > JMP                                                      ->21
         15    >   INIT_FCALL                                               'sprintf'
         16        SEND_VAR                                                 !2
         17        SEND_VAR                                                 !0
         18        SEND_VAR                                                 !1
         19        DO_ICALL                                         $7      
         20        QM_ASSIGN                                        ~6      $7
         21    > > RETURN                                                   ~6
   26    22*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FncsGq%3A24%240

Function %00%7Bclosure%7D%2Fin%2FncsGq%3A44%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ncsGq
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $key, !1 = $value, !2 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
          3        FETCH_DIM_R                                      ~3      !1, !2
          4      > RETURN                                                   ~3
          5*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FncsGq%3A44%241

Function %00%7Bclosure%7D%2Fin%2FncsGq%3A47%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ncsGq
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $key, !1 = $value, !2 = $property
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
          3        FETCH_OBJ_R                                      ~3      !1, !2
          4      > RETURN                                                   ~3
          5*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FncsGq%3A47%242

Function %00%7Bclosure%7D%2Fin%2FncsGq%3A54%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ncsGq
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $value, !1 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        INIT_USER_CALL                                1          'call_user_func', !1
          3        SEND_USER                                                !0
          4        DO_FCALL                                      0  $2      
          5        BOOL_NOT                                         ~3      $2
          6      > RETURN                                                   ~3
          7*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FncsGq%3A54%243

Class Collection:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ncsGq
function name:  __construct
number of ops:  4
compiled vars:  !0 = $items
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV_INIT                                        !0      <array>
    6     1        ASSIGN_OBJ                                               '_items'
          2        OP_DATA                                                  !0
    7     3      > RETURN                                                   null

End of function __construct

Function filter:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 13
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 12
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/ncsGq
function name:  filter
number of ops:  19
compiled vars:  !0 = $callback, !1 = $value, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
    9     1        FETCH_OBJ_R                                      ~3      '_items'
          2      > FE_RESET_R                                       $4      ~3, ->13
          3    > > FE_FETCH_R                                       ~5      $4, !1, ->13
          4    >   ASSIGN                                                   !2, ~5
   10     5        INIT_USER_CALL                                1          'call_user_func', !0
          6        SEND_USER                                                !1
          7        DO_FCALL                                      0  $7      
          8        BOOL_NOT                                         ~8      $7
          9      > JMPZ                                                     ~8, ->12
   11    10    >   FETCH_OBJ_UNSET                                  $9      '_items'
         11        UNSET_DIM                                                $9, !2
    9    12    > > JMP                                                      ->3
         13    >   FE_FREE                                                  $4
   12    14        FETCH_THIS                                       ~10     
         15        VERIFY_RETURN_TYPE                                       ~10
         16      > RETURN                                                   ~10
   13    17*       VERIFY_RETURN_TYPE                                       
         18*     > RETURN                                                   null

End of function filter

Function map:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 13
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/ncsGq
function name:  map
number of ops:  19
compiled vars:  !0 = $callback, !1 = $value, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        FETCH_OBJ_R                                      ~3      '_items'
          2      > FE_RESET_R                                       $4      ~3, ->13
          3    > > FE_FETCH_R                                       ~5      $4, !1, ->13
          4    >   ASSIGN                                                   !2, ~5
   16     5        INIT_USER_CALL                                2          'call_user_func', !0
          6        SEND_USER                                                !2
          7        SEND_USER                                                !1
          8        DO_FCALL                                      0  $9      
          9        FETCH_OBJ_W                                      $7      '_items'
         10        ASSIGN_DIM                                               $7, !2
         11        OP_DATA                                                  $9
   15    12      > JMP                                                      ->3
         13    >   FE_FREE                                                  $4
   17    14        FETCH_THIS                                       ~10     
         15        VERIFY_RETURN_TYPE                                       ~10
         16      > RETURN                                                   ~10
   18    17*       VERIFY_RETURN_TYPE                                       
         18*     > RETURN                                                   null

End of function map

Function reindex:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ncsGq
function name:  reindex
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   INIT_FCALL                                               'array_values'
          1        FETCH_OBJ_R                                      ~1      '_items'
          2        SEND_VAL                                                 ~1
          3        DO_ICALL                                         $2      
          4        ASSIGN_OBJ                                               '_items'
          5        OP_DATA                                                  $2
   21     6        FETCH_THIS                                       ~3      
          7        VERIFY_RETURN_TYPE                                       ~3
          8      > RETURN                                                   ~3
   22     9*       VERIFY_RETURN_TYPE                                       
         10*     > RETURN                                                   null

End of function reindex

Function sprintf:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ncsGq
function name:  sprintf
number of ops:  10
compiled vars:  !0 = $format
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   24     1        INIT_METHOD_CALL                                         'map'
          2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FncsGq%3A24%240'
          3        BIND_LEXICAL                                             ~1, !0
   26     4        SEND_VAL_EX                                              ~1
          5        DO_FCALL                                      0  $2      
          6        VERIFY_RETURN_TYPE                                       $2
          7      > RETURN                                                   $2
   27     8*       VERIFY_RETURN_TYPE                                       
          9*     > RETURN                                                   null

End of function sprintf

Function keys:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ncsGq
function name:  keys
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   INIT_FCALL                                               'array_keys'
          1        FETCH_OBJ_R                                      ~1      '_items'
          2        SEND_VAL                                                 ~1
          3        DO_ICALL                                         $2      
          4        ASSIGN_OBJ                                               '_items'
          5        OP_DATA                                                  $2
   30     6        FETCH_THIS                                       ~3      
          7        VERIFY_RETURN_TYPE                                       ~3
          8      > RETURN                                                   ~3
   31     9*       VERIFY_RETURN_TYPE                                       
         10*     > RETURN                                                   null

End of function keys

Function implode:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 14
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/ncsGq
function name:  implode
number of ops:  19
compiled vars:  !0 = $delimiter, !1 = $output, !2 = $first, !3 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV_INIT                                        !0      ''
   33     1        ASSIGN                                                   !1, ''
   34     2        ASSIGN                                                   !2, <true>
   35     3        FETCH_OBJ_R                                      ~6      '_items'
          4      > FE_RESET_R                                       $7      ~6, ->14
          5    > > FE_FETCH_R                                               $7, !3, ->14
   36     6    > > JMPZ                                                     !2, ->10
   37     7    >   ASSIGN_OP                                     8          !1, !3
   38     8        ASSIGN                                                   !2, <false>
          9      > JMP                                                      ->13
   40    10    >   NOP                                                      
         11        FAST_CONCAT                                      ~10     !0, !3
         12        ASSIGN_OP                                     8          !1, ~10
   35    13    > > JMP                                                      ->5
         14    >   FE_FREE                                                  $7
   41    15        VERIFY_RETURN_TYPE                                       !1
         16      > RETURN                                                   !1
   42    17*       VERIFY_RETURN_TYPE                                       
         18*     > RETURN                                                   null

End of function implode

Function index:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ncsGq
function name:  index
number of ops:  7
compiled vars:  !0 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
   44     1        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FncsGq%3A44%241'
          2        BIND_LEXICAL                                             ~1, !0
          3        VERIFY_RETURN_TYPE                                       ~1
          4      > RETURN                                                   ~1
   45     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function index

Function property:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ncsGq
function name:  property
number of ops:  7
compiled vars:  !0 = $property
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
   47     1        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FncsGq%3A47%242'
          2        BIND_LEXICAL                                             ~1, !0
          3        VERIFY_RETURN_TYPE                                       ~1
          4      > RETURN                                                   ~1
   48     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function property

Function values:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ncsGq
function name:  values
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   FETCH_OBJ_R                                      ~0      '_items'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
          3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function values

End of class Collection.

Class Filter:
Function not:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ncsGq
function name:  not
number of ops:  7
compiled vars:  !0 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
   54     1        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FncsGq%3A54%243'
          2        BIND_LEXICAL                                             ~1, !0
          3        VERIFY_RETURN_TYPE                                       ~1
          4      > RETURN                                                   ~1
   55     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function not

End of class Filter.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176 ms | 1416 KiB | 21 Q