3v4l.org

run code in 300+ PHP versions simultaneously
<?php class User { } class UserProvider { public function getServices() { return ['user']; } public function user() { return new User(); } } $provider = new UserProvider(); $services = array_map(function($factoryName) use($provider) { return $provider->{$factoryName}(); // <-- dynamic call }, $provider->getServices()); var_dump($services);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4Naug
function name:  (null)
number of ops:  16
compiled vars:  !0 = $provider, !1 = $services
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   NEW                                              $2      'UserProvider'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   19     3        INIT_FCALL                                               'array_map'
          4        DECLARE_LAMBDA_FUNCTION                          ~5      [0]
          5        BIND_LEXICAL                                             ~5, !0
   23     6        SEND_VAL                                                 ~5
          7        INIT_METHOD_CALL                                         !0, 'getServices'
          8        DO_FCALL                                      0  $6      
          9        SEND_VAR                                                 $6
   19    10        DO_ICALL                                         $7      
         11        ASSIGN                                                   !1, $7
   25    12        INIT_FCALL                                               'var_dump'
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                                 
         15      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4Naug
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $factoryName, !1 = $provider
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   21     2        INIT_METHOD_CALL                                         !1, !0
          3        DO_FCALL                                      0  $2      
          4      > RETURN                                                   $2
   23     5*     > RETURN                                                   null

End of Dynamic Function 0

Class User: [no user functions]
Class UserProvider:
Function getservices:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4Naug
function name:  getServices
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E > > RETURN                                                   <array>
   10     1*     > RETURN                                                   null

End of function getservices

Function user:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4Naug
function name:  user
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   NEW                                              $0      'User'
          1        DO_FCALL                                      0          
          2      > RETURN                                                   $0
   14     3*     > RETURN                                                   null

End of function user

End of class UserProvider.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
184.68 ms | 1439 KiB | 15 Q