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); } 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 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 property(string $property): callable { return function ($key, $value) use ($property) { return $value->$property; }; } } } namespace { use Acme\Collection; echo (new Collection([ 'one', 'two', (object)['foo' => 'FOO', 'bar' => 'BAR', 'baz' => 'BAZ'], 'three', (object)['bar' => 'BAR', 'qux' => 'QUX'], ])) ->filter('is_object') ->map(Collection::property('bar')) ->reindex() ->sprintf('(%s,%s)') ->implode('_'); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UaDgl
function name:  (null)
number of ops:  29
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   NEW                                              $0      'Acme%5CCollection'
   58     1        INIT_ARRAY                                       ~1      'one'
   59     2        ADD_ARRAY_ELEMENT                                ~1      'two'
   60     3        CAST                                          8  ~2      <array>
          4        ADD_ARRAY_ELEMENT                                ~1      ~2
   61     5        ADD_ARRAY_ELEMENT                                ~1      'three'
   62     6        CAST                                          8  ~3      <array>
          7        ADD_ARRAY_ELEMENT                                ~1      ~3
          8        SEND_VAL_EX                                              ~1
          9        DO_FCALL                                      0          
   64    10        INIT_METHOD_CALL                                         $0, 'filter'
         11        SEND_VAL_EX                                              'is_object'
         12        DO_FCALL                                      0  $5      
   65    13        INIT_METHOD_CALL                                         $5, 'map'
         14        INIT_STATIC_METHOD_CALL                                  'Acme%5CCollection', 'property'
         15        SEND_VAL                                                 'bar'
         16        DO_FCALL                                      0  $6      
         17        SEND_VAR_NO_REF_EX                                       $6
         18        DO_FCALL                                      0  $7      
   66    19        INIT_METHOD_CALL                                         $7, 'reindex'
         20        DO_FCALL                                      0  $8      
   67    21        INIT_METHOD_CALL                                         $8, 'sprintf'
         22        SEND_VAL_EX                                              '%28%25s%2C%25s%29'
         23        DO_FCALL                                      0  $9      
   68    24        INIT_METHOD_CALL                                         $9, 'implode'
         25        SEND_VAL_EX                                              '_'
         26        DO_FCALL                                      0  $10     
         27        ECHO                                                     $10
   69    28      > RETURN                                                   1

Function %00acme%5C%7Bclosure%7D%2Fin%2FUaDgl%3A27%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/UaDgl
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
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   28     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
   29     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
   30    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
   31    22*     > RETURN                                                   null

End of function %00acme%5C%7Bclosure%7D%2Fin%2FUaDgl%3A27%240

Function %00acme%5C%7Bclosure%7D%2Fin%2FUaDgl%3A47%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UaDgl
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
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   48     3        FETCH_OBJ_R                                      ~3      !1, !2
          4      > RETURN                                                   ~3
   49     5*     > RETURN                                                   null

End of function %00acme%5C%7Bclosure%7D%2Fin%2FUaDgl%3A47%241

Class Acme\Collection:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UaDgl
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/UaDgl
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/UaDgl
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/UaDgl
function name:  reindex
number of ops:  9
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        VERIFY_RETURN_TYPE                                       
          8      > 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/UaDgl
function name:  sprintf
number of ops:  10
compiled vars:  !0 = $format
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   27     1        INIT_METHOD_CALL                                         'map'
          2        DECLARE_LAMBDA_FUNCTION                                  '%00acme%5C%7Bclosure%7D%2Fin%2FUaDgl%3A27%240'
          3        BIND_LEXICAL                                             ~1, !0
   31     4        SEND_VAL_EX                                              ~1
          5        DO_FCALL                                      0  $2      
          6        VERIFY_RETURN_TYPE                                       $2
          7      > RETURN                                                   $2
   32     8*       VERIFY_RETURN_TYPE                                       
          9*     > RETURN                                                   null

End of function sprintf

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/UaDgl
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
-------------------------------------------------------------------------------------
   33     0  E >   RECV_INIT                                        !0      ''
   34     1        ASSIGN                                                   !1, ''
   35     2        ASSIGN                                                   !2, <true>
   36     3        FETCH_OBJ_R                                      ~6      '_items'
          4      > FE_RESET_R                                       $7      ~6, ->14
          5    > > FE_FETCH_R                                               $7, !3, ->14
   37     6    > > JMPZ                                                     !2, ->10
   38     7    >   ASSIGN_OP                                     8          !1, !3
   39     8        ASSIGN                                                   !2, <false>
          9      > JMP                                                      ->13
   41    10    >   NOP                                                      
         11        FAST_CONCAT                                      ~10     !0, !3
         12        ASSIGN_OP                                     8          !1, ~10
   36    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 property:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UaDgl
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                                  '%00acme%5C%7Bclosure%7D%2Fin%2FUaDgl%3A47%241'
          2        BIND_LEXICAL                                             ~1, !0
   49     3        VERIFY_RETURN_TYPE                                       ~1
          4      > RETURN                                                   ~1
   50     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function property

End of class Acme\Collection.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.13 ms | 1412 KiB | 21 Q