3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyService { function preprocess(array &$variables): void { $variables['x'] = 'X'; } } class Drupal { static function service($id): object { return new MyService(); } } class ServiceCallback { static function __callStatic(string $f, array $args) { ['service' => $service_id, 'method' => $method] = unserialize($f); $service = \Drupal::service($service_id); $service->$method(...$args); } } $variables = []; $callback = ['ServiceCallback', serialize(['service' => 'myservice', 'method' => 'preprocess'])]; call_user_func_array($callback, [&$variables]); var_export($variables);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JBk1u
function name:  (null)
number of ops:  16
compiled vars:  !0 = $variables, !1 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   ASSIGN                                                   !0, <array>
   25     1        INIT_ARRAY                                       ~3      'ServiceCallback'
          2        INIT_FCALL                                               'serialize'
          3        SEND_VAL                                                 <array>
          4        DO_ICALL                                         $4      
          5        ADD_ARRAY_ELEMENT                                ~3      $4
          6        ASSIGN                                                   !1, ~3
   26     7        INIT_USER_CALL                                0          'call_user_func_array', !1
          8        INIT_ARRAY                                       ~6      !0
          9        SEND_ARRAY                                               ~6
         10        CHECK_UNDEF_ARGS                                         
         11        DO_FCALL                                      1          
   28    12        INIT_FCALL                                               'var_export'
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                                 
         15      > RETURN                                                   1

Class MyService:
Function preprocess:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JBk1u
function name:  preprocess
number of ops:  4
compiled vars:  !0 = $variables
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        ASSIGN_DIM                                               !0, 'x'
          2        OP_DATA                                                  'X'
    6     3      > RETURN                                                   null

End of function preprocess

End of class MyService.

Class Drupal:
Function service:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JBk1u
function name:  service
number of ops:  7
compiled vars:  !0 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   11     1        NEW                                              $1      'MyService'
          2        DO_FCALL                                      0          
          3        VERIFY_RETURN_TYPE                                       $1
          4      > RETURN                                                   $1
   12     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function service

End of class Drupal.

Class ServiceCallback:
Function __callstatic:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JBk1u
function name:  __callStatic
number of ops:  19
compiled vars:  !0 = $f, !1 = $args, !2 = $service_id, !3 = $method, !4 = $service
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   17     2        INIT_FCALL                                               'unserialize'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $5      
          5        FETCH_LIST_R                                     $6      $5, 'service'
          6        ASSIGN                                                   !2, $6
          7        FETCH_LIST_R                                     $8      $5, 'method'
          8        ASSIGN                                                   !3, $8
          9        FREE                                                     $5
   18    10        INIT_STATIC_METHOD_CALL                                  'Drupal', 'service'
         11        SEND_VAR                                                 !2
         12        DO_FCALL                                      0  $10     
         13        ASSIGN                                                   !4, $10
   19    14        INIT_METHOD_CALL                                         !4, !3
         15        SEND_UNPACK                                              !1
         16        CHECK_UNDEF_ARGS                                         
         17        DO_FCALL                                      1          
   20    18      > RETURN                                                   null

End of function __callstatic

End of class ServiceCallback.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
127.07 ms | 1439 KiB | 16 Q