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 index($index): self { return $this->map(function ($key, $value) use ($index) { return $value[$index]; }); } public function property(string $property): self { return $this->map(function ($key, $value) use ($property) { return $value->$property; }); } 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 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') ->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/gMQSO
function name:  (null)
number of ops:  23
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   NEW                                              $0      'Collection'
   56     1        SEND_VAL_EX                                              <array>
          2        DO_FCALL                                      0          
   63     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      
   64     9        INIT_METHOD_CALL                                         $3, 'filter'
         10        SEND_VAL_EX                                              'is_array'
         11        DO_FCALL                                      0  $4      
   65    12        INIT_METHOD_CALL                                         $4, 'index'
         13        SEND_VAL_EX                                              'foo'
         14        DO_FCALL                                      0  $5      
   68    15        INIT_METHOD_CALL                                         $5, 'sprintf'
         16        SEND_VAL_EX                                              '%28%25s%2C%25s%29'
         17        DO_FCALL                                      0  $6      
   69    18        INIT_METHOD_CALL                                         $6, 'implode'
         19        SEND_VAL_EX                                              '_'
         20        DO_FCALL                                      0  $7      
         21        ECHO                                                     $7
         22      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FgMQSO%3A21%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/gMQSO
function name:  {closure}
number of ops:  23
compiled vars:  !0 = $key, !1 = $value, !2 = $format
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   22     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
   23    22*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FgMQSO%3A21%240

Function %00%7Bclosure%7D%2Fin%2FgMQSO%3A30%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gMQSO
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $key, !1 = $value, !2 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     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%2FgMQSO%3A30%241

Function %00%7Bclosure%7D%2Fin%2FgMQSO%3A33%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gMQSO
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $key, !1 = $value, !2 = $property
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     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%2FgMQSO%3A33%242

Function %00%7Bclosure%7D%2Fin%2FgMQSO%3A51%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gMQSO
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $value, !1 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     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%2FgMQSO%3A51%243

Class Collection:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gMQSO
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/gMQSO
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
          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
         10    >   FETCH_OBJ_UNSET                                  $9      '_items'
         11        UNSET_DIM                                                $9, !2
         12    > > JMP                                                      ->3
         13    >   FE_FREE                                                  $4
   10    14        FETCH_THIS                                       ~10     
         15        VERIFY_RETURN_TYPE                                       ~10
         16      > RETURN                                                   ~10
   11    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/gMQSO
function name:  map
number of ops:  19
compiled vars:  !0 = $callback, !1 = $value, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     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
          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
         12      > JMP                                                      ->3
         13    >   FE_FREE                                                  $4
   14    14        FETCH_THIS                                       ~10     
         15        VERIFY_RETURN_TYPE                                       ~10
         16      > RETURN                                                   ~10
   15    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/gMQSO
function name:  reindex
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     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
   18     6        FETCH_THIS                                       ~3      
          7        VERIFY_RETURN_TYPE                                       ~3
          8      > RETURN                                                   ~3
   19     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/gMQSO
function name:  sprintf
number of ops:  10
compiled vars:  !0 = $format
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   21     1        INIT_METHOD_CALL                                         'map'
          2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FgMQSO%3A21%240'
          3        BIND_LEXICAL                                             ~1, !0
   23     4        SEND_VAL_EX                                              ~1
          5        DO_FCALL                                      0  $2      
          6        VERIFY_RETURN_TYPE                                       $2
          7      > RETURN                                                   $2
   24     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/gMQSO
function name:  keys
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     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
   27     6        FETCH_THIS                                       ~3      
          7        VERIFY_RETURN_TYPE                                       ~3
          8      > RETURN                                                   ~3
   28     9*       VERIFY_RETURN_TYPE                                       
         10*     > RETURN                                                   null

End of function keys

Function index:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gMQSO
function name:  index
number of ops:  10
compiled vars:  !0 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   30     1        INIT_METHOD_CALL                                         'map'
          2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FgMQSO%3A30%241'
          3        BIND_LEXICAL                                             ~1, !0
          4        SEND_VAL_EX                                              ~1
          5        DO_FCALL                                      0  $2      
          6        VERIFY_RETURN_TYPE                                       $2
          7      > RETURN                                                   $2
   31     8*       VERIFY_RETURN_TYPE                                       
          9*     > 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/gMQSO
function name:  property
number of ops:  10
compiled vars:  !0 = $property
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
   33     1        INIT_METHOD_CALL                                         'map'
          2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FgMQSO%3A33%242'
          3        BIND_LEXICAL                                             ~1, !0
          4        SEND_VAL_EX                                              ~1
          5        DO_FCALL                                      0  $2      
          6        VERIFY_RETURN_TYPE                                       $2
          7      > RETURN                                                   $2
   34     8*       VERIFY_RETURN_TYPE                                       
          9*     > RETURN                                                   null

End of function property

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/gMQSO
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
-------------------------------------------------------------------------------------
   35     0  E >   RECV_INIT                                        !0      ''
   36     1        ASSIGN                                                   !1, ''
   37     2        ASSIGN                                                   !2, <true>
   38     3        FETCH_OBJ_R                                      ~6      '_items'
          4      > FE_RESET_R                                       $7      ~6, ->14
          5    > > FE_FETCH_R                                               $7, !3, ->14
   39     6    > > JMPZ                                                     !2, ->10
   40     7    >   ASSIGN_OP                                     8          !1, !3
   41     8        ASSIGN                                                   !2, <false>
          9      > JMP                                                      ->13
   43    10    >   NOP                                                      
         11        FAST_CONCAT                                      ~10     !0, !3
         12        ASSIGN_OP                                     8          !1, ~10
   38    13    > > JMP                                                      ->5
         14    >   FE_FREE                                                  $7
   44    15        VERIFY_RETURN_TYPE                                       !1
         16      > RETURN                                                   !1
   45    17*       VERIFY_RETURN_TYPE                                       
         18*     > RETURN                                                   null

End of function implode

Function values:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gMQSO
function name:  values
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     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/gMQSO
function name:  not
number of ops:  7
compiled vars:  !0 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
   51     1        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FgMQSO%3A51%243'
          2        BIND_LEXICAL                                             ~1, !0
          3        VERIFY_RETURN_TYPE                                       ~1
          4      > RETURN                                                   ~1
   52     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:
165.13 ms | 1411 KiB | 22 Q