3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getGreeting(MapInterface $user): string { $fullName = []; $fullNameSegments = ['first_name', 'last_name']; foreach ($fullNameSegments as $segment) { if ($user->has($segment)) { $fullName[] = $user->get($segment); } } return implode(' ', $fullName); } interface MapInterface { public function get(string $key); public function has(string $key): bool; } class Map implements MapInterface { protected $data; public function __construct(array $data) { $this->data = $data; } public function get(string $key) { if (!array_key_exists($key, $this->data)) { throw new RangeException(sprintf('Key %1$s not found', $key)); } return $this->data[$key]; } public function has(string $key): bool { return array_key_exists($key, $this->data); } } $user = new Map([ 'first_name' => 'Xedin', 'last_name' => 'Unknown', 'id' => '12345', ]); assert($user instanceof MapInterface); echo getGreeting($user);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kn7II
function name:  (null)
number of ops:  16
compiled vars:  !0 = $user
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   DECLARE_CLASS                                            'map'
   47     1        NEW                                              $1      'Map'
   48     2        SEND_VAL_EX                                              <array>
          3        DO_FCALL                                      0          
   47     4        ASSIGN                                                   !0, $1
   52     5        ASSERT_CHECK                                             
          6        INIT_FCALL                                               'assert'
          7        INSTANCEOF                                       ~4      !0, 'MapInterface'
          8        SEND_VAL                                                 ~4
          9        SEND_VAL                                                 'assert%28%24user+instanceof+MapInterface%29'
         10        DO_ICALL                                                 
   53    11        INIT_FCALL                                               'getgreeting'
         12        SEND_VAR                                                 !0
         13        DO_FCALL                                      0  $6      
         14        ECHO                                                     $6
         15      > RETURN                                                   1

Function getgreeting:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 15
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 14
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/kn7II
function name:  getGreeting
number of ops:  24
compiled vars:  !0 = $user, !1 = $fullName, !2 = $fullNameSegments, !3 = $segment
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, <array>
    5     2        ASSIGN                                                   !2, <array>
    7     3      > FE_RESET_R                                       $6      !2, ->15
          4    > > FE_FETCH_R                                               $6, !3, ->15
    8     5    >   INIT_METHOD_CALL                                         !0, 'has'
          6        SEND_VAR_EX                                              !3
          7        DO_FCALL                                      0  $7      
          8      > JMPZ                                                     $7, ->14
    9     9    >   INIT_METHOD_CALL                                         !0, 'get'
         10        SEND_VAR_EX                                              !3
         11        DO_FCALL                                      0  $9      
         12        ASSIGN_DIM                                               !1
         13        OP_DATA                                                  $9
    7    14    > > JMP                                                      ->4
         15    >   FE_FREE                                                  $6
   13    16        INIT_FCALL                                               'implode'
         17        SEND_VAL                                                 '+'
         18        SEND_VAR                                                 !1
         19        DO_ICALL                                         $10     
         20        VERIFY_RETURN_TYPE                                       $10
         21      > RETURN                                                   $10
   14    22*       VERIFY_RETURN_TYPE                                       
         23*     > RETURN                                                   null

End of function getgreeting

Class MapInterface:
Function get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kn7II
function name:  get
number of ops:  2
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function get

Function has:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kn7II
function name:  has
number of ops:  3
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        VERIFY_RETURN_TYPE                                       
          2      > RETURN                                                   null

End of function has

End of class MapInterface.

Class Map:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kn7II
function name:  __construct
number of ops:  4
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   29     1        ASSIGN_OBJ                                               'data'
          2        OP_DATA                                                  !0
   30     3      > RETURN                                                   null

End of function __construct

Function get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kn7II
function name:  get
number of ops:  17
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
   34     1        FETCH_OBJ_R                                      ~1      'data'
          2        ARRAY_KEY_EXISTS                                 ~2      !0, ~1
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPZ                                                     ~3, ->13
   35     5    >   NEW                                              $4      'RangeException'
          6        INIT_FCALL                                               'sprintf'
          7        SEND_VAL                                                 'Key+%251%24s+not+found'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $5      
         10        SEND_VAR_NO_REF_EX                                       $5
         11        DO_FCALL                                      0          
         12      > THROW                                         0          $4
   38    13    >   FETCH_OBJ_R                                      ~7      'data'
         14        FETCH_DIM_R                                      ~8      ~7, !0
         15      > RETURN                                                   ~8
   39    16*     > RETURN                                                   null

End of function get

Function has:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kn7II
function name:  has
number of ops:  7
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
   43     1        FETCH_OBJ_R                                      ~1      'data'
          2        ARRAY_KEY_EXISTS                                 ~2      !0, ~1
          3        VERIFY_RETURN_TYPE                                       ~2
          4      > RETURN                                                   ~2
   44     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function has

End of class Map.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.27 ms | 1407 KiB | 20 Q