3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types = 1); namespace Acme { 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 static function not(callable $callback): callable { return function ($key, $value) use ($callback) { return !call_user_func($callback, $key, $value); }; } public function values(): array { return $this->_items; } } } namespace { use Acme\Collection; echo (new Collection([ 'one', 'two', (object)['foo' => 'FOO', 'bar' => 'BAR', 'baz' => 'BAZ'], 'three', (object)['bar' => 'BAR', 'qux' => 'QUX'], ])) ->filter(Collection::not('is_string')) ->map(Collection::property('bar')) //->reindex() ->keys() //->sprintf('(%s,%s)') ->implode('_'); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WIeXp
function name:  (null)
number of ops:  29
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   75     0  E >   NEW                                              $0      'Acme%5CCollection'
   76     1        INIT_ARRAY                                       ~1      'one'
   77     2        ADD_ARRAY_ELEMENT                                ~1      'two'
   78     3        CAST                                          8  ~2      <array>
          4        ADD_ARRAY_ELEMENT                                ~1      ~2
   79     5        ADD_ARRAY_ELEMENT                                ~1      'three'
   80     6        CAST                                          8  ~3      <array>
          7        ADD_ARRAY_ELEMENT                                ~1      ~3
          8        SEND_VAL_EX                                              ~1
          9        DO_FCALL                                      0          
   82    10        INIT_METHOD_CALL                                         $0, 'filter'
         11        INIT_STATIC_METHOD_CALL                                  'Acme%5CCollection', 'not'
         12        SEND_VAL                                                 'is_string'
         13        DO_FCALL                                      0  $5      
         14        SEND_VAR_NO_REF_EX                                       $5
         15        DO_FCALL                                      0  $6      
   83    16        INIT_METHOD_CALL                                         $6, 'map'
         17        INIT_STATIC_METHOD_CALL                                  'Acme%5CCollection', 'property'
         18        SEND_VAL                                                 'bar'
         19        DO_FCALL                                      0  $7      
         20        SEND_VAR_NO_REF_EX                                       $7
         21        DO_FCALL                                      0  $8      
   85    22        INIT_METHOD_CALL                                         $8, 'keys'
         23        DO_FCALL                                      0  $9      
   87    24        INIT_METHOD_CALL                                         $9, 'implode'
         25        SEND_VAL_EX                                              '_'
         26        DO_FCALL                                      0  $10     
         27        ECHO                                                     $10
   88    28      > RETURN                                                   1

Function %00acme%5C%7Bclosure%7D%2Fin%2FWIeXp%3A28%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/WIeXp
function name:  Acme\{closure}
number of ops:  23
compiled vars:  !0 = $key, !1 = $value, !2 = $format
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   29     3        INIT_NS_FCALL_BY_NAME                                    'Acme%5Csubstr_count'
          4        SEND_VAR_EX                                              !2
          5        SEND_VAL_EX                                              '%25s'
          6        DO_FCALL                                      0  $3      
          7        IS_IDENTICAL                                             $3, 1
          8      > JMPZ                                                     ~4, ->15
   30     9    >   INIT_NS_FCALL_BY_NAME                                    'Acme%5Csprintf'
         10        SEND_VAR_EX                                              !2
         11        SEND_VAR_EX                                              !1
         12        DO_FCALL                                      0  $5      
         13        QM_ASSIGN                                        ~6      $5
         14      > JMP                                                      ->21
   31    15    >   INIT_NS_FCALL_BY_NAME                                    'Acme%5Csprintf'
         16        SEND_VAR_EX                                              !2
         17        SEND_VAR_EX                                              !0
         18        SEND_VAR_EX                                              !1
         19        DO_FCALL                                      0  $7      
         20        QM_ASSIGN                                        ~6      $7
         21    > > RETURN                                                   ~6
   32    22*     > RETURN                                                   null

End of function %00acme%5C%7Bclosure%7D%2Fin%2FWIeXp%3A28%240

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

End of function %00acme%5C%7Bclosure%7D%2Fin%2FWIeXp%3A52%241

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

End of function %00acme%5C%7Bclosure%7D%2Fin%2FWIeXp%3A57%242

Function %00acme%5C%7Bclosure%7D%2Fin%2FWIeXp%3A62%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WIeXp
function name:  Acme\{closure}
number of ops:  11
compiled vars:  !0 = $key, !1 = $value, !2 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   63     3        INIT_NS_FCALL_BY_NAME                                    'Acme%5Ccall_user_func'
          4        SEND_VAR_EX                                              !2
          5        SEND_VAR_EX                                              !0
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0  $3      
          8        BOOL_NOT                                         ~4      $3
          9      > RETURN                                                   ~4
   64    10*     > RETURN                                                   null

End of function %00acme%5C%7Bclosure%7D%2Fin%2FWIeXp%3A62%243

Class Acme\Collection:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WIeXp
function name:  __construct
number of ops:  4
compiled vars:  !0 = $items
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV_INIT                                        !0      <array>
    7     1        ASSIGN_OBJ                                               '_items'
          2        OP_DATA                                                  !0
    8     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 = 14
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 14
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 13
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/WIeXp
function name:  filter
number of ops:  20
compiled vars:  !0 = $callback, !1 = $value, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        FETCH_OBJ_R                                      ~3      '_items'
          2      > FE_RESET_R                                       $4      ~3, ->14
          3    > > FE_FETCH_R                                       ~5      $4, !1, ->14
          4    >   ASSIGN                                                   !2, ~5
   11     5        INIT_NS_FCALL_BY_NAME                                    'Acme%5Ccall_user_func'
          6        SEND_VAR_EX                                              !0
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0  $7      
          9        BOOL_NOT                                         ~8      $7
         10      > JMPZ                                                     ~8, ->13
   12    11    >   FETCH_OBJ_UNSET                                  $9      '_items'
         12        UNSET_DIM                                                $9, !2
   10    13    > > JMP                                                      ->3
         14    >   FE_FREE                                                  $4
   15    15        FETCH_THIS                                       ~10     
         16        VERIFY_RETURN_TYPE                                       ~10
         17      > RETURN                                                   ~10
   16    18*       VERIFY_RETURN_TYPE                                       
         19*     > 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 = 14
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 14
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/WIeXp
function name:  map
number of ops:  20
compiled vars:  !0 = $callback, !1 = $value, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   18     1        FETCH_OBJ_R                                      ~3      '_items'
          2      > FE_RESET_R                                       $4      ~3, ->14
          3    > > FE_FETCH_R                                       ~5      $4, !1, ->14
          4    >   ASSIGN                                                   !2, ~5
   19     5        INIT_NS_FCALL_BY_NAME                                    'Acme%5Ccall_user_func'
          6        SEND_VAR_EX                                              !0
          7        SEND_VAR_EX                                              !2
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0  $9      
         10        FETCH_OBJ_W                                      $7      '_items'
         11        ASSIGN_DIM                                               $7, !2
         12        OP_DATA                                                  $9
   18    13      > JMP                                                      ->3
         14    >   FE_FREE                                                  $4
   21    15        FETCH_THIS                                       ~10     
         16        VERIFY_RETURN_TYPE                                       ~10
         17      > RETURN                                                   ~10
   22    18*       VERIFY_RETURN_TYPE                                       
         19*     > 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/WIeXp
function name:  reindex
number of ops:  12
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   INIT_NS_FCALL_BY_NAME                                    'Acme%5Carray_values'
          1        CHECK_FUNC_ARG                                           
          2        FETCH_OBJ_FUNC_ARG                               $1      '_items'
          3        SEND_FUNC_ARG                                            $1
          4        DO_FCALL                                      0  $2      
          5        ASSIGN_OBJ                                               '_items'
          6        OP_DATA                                                  $2
   25     7        FETCH_THIS                                       ~3      
          8        VERIFY_RETURN_TYPE                                       ~3
          9      > RETURN                                                   ~3
   26    10*       VERIFY_RETURN_TYPE                                       
         11*     > 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/WIeXp
function name:  sprintf
number of ops:  10
compiled vars:  !0 = $format
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   28     1        INIT_METHOD_CALL                                         'map'
          2        DECLARE_LAMBDA_FUNCTION                                  '%00acme%5C%7Bclosure%7D%2Fin%2FWIeXp%3A28%240'
          3        BIND_LEXICAL                                             ~1, !0
   32     4        SEND_VAL_EX                                              ~1
          5        DO_FCALL                                      0  $2      
          6        VERIFY_RETURN_TYPE                                       $2
          7      > RETURN                                                   $2
   33     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/WIeXp
function name:  keys
number of ops:  12
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   INIT_NS_FCALL_BY_NAME                                    'Acme%5Carray_keys'
          1        CHECK_FUNC_ARG                                           
          2        FETCH_OBJ_FUNC_ARG                               $1      '_items'
          3        SEND_FUNC_ARG                                            $1
          4        DO_FCALL                                      0  $2      
          5        ASSIGN_OBJ                                               '_items'
          6        OP_DATA                                                  $2
   36     7        FETCH_THIS                                       ~3      
          8        VERIFY_RETURN_TYPE                                       ~3
          9      > RETURN                                                   ~3
   37    10*       VERIFY_RETURN_TYPE                                       
         11*     > 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/WIeXp
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
-------------------------------------------------------------------------------------
   38     0  E >   RECV_INIT                                        !0      ''
   39     1        ASSIGN                                                   !1, ''
   40     2        ASSIGN                                                   !2, <true>
   41     3        FETCH_OBJ_R                                      ~6      '_items'
          4      > FE_RESET_R                                       $7      ~6, ->14
          5    > > FE_FETCH_R                                               $7, !3, ->14
   42     6    > > JMPZ                                                     !2, ->10
   43     7    >   ASSIGN_OP                                     8          !1, !3
   44     8        ASSIGN                                                   !2, <false>
          9      > JMP                                                      ->13
   46    10    >   NOP                                                      
         11        FAST_CONCAT                                      ~10     !0, !3
         12        ASSIGN_OP                                     8          !1, ~10
   41    13    > > JMP                                                      ->5
         14    >   FE_FREE                                                  $7
   49    15        VERIFY_RETURN_TYPE                                       !1
         16      > RETURN                                                   !1
   50    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/WIeXp
function name:  index
number of ops:  7
compiled vars:  !0 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   RECV                                             !0      
   52     1        DECLARE_LAMBDA_FUNCTION                                  '%00acme%5C%7Bclosure%7D%2Fin%2FWIeXp%3A52%241'
          2        BIND_LEXICAL                                             ~1, !0
   54     3        VERIFY_RETURN_TYPE                                       ~1
          4      > RETURN                                                   ~1
   55     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/WIeXp
function name:  property
number of ops:  7
compiled vars:  !0 = $property
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   RECV                                             !0      
   57     1        DECLARE_LAMBDA_FUNCTION                                  '%00acme%5C%7Bclosure%7D%2Fin%2FWIeXp%3A57%242'
          2        BIND_LEXICAL                                             ~1, !0
   59     3        VERIFY_RETURN_TYPE                                       ~1
          4      > RETURN                                                   ~1
   60     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function property

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

End of function not

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

End of function values

End of class Acme\Collection.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.74 ms | 1424 KiB | 23 Q