3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait Delegator { private $delegates = []; protected function delegate($object, array $methods) { foreach ($methods as $method) { $this->delegates[$method] = $object; } } function __call($method, array $args) { if (isset($this->delegates[$method])) { return call_user_func_array([$this->delegates[$method], $method], $args); } throw new Exception('Method not found!'); } } class AuthService { function authenticate($username, $password) { echo 'Doing the auth for ' . $username . '!'; } } class UserModel { use Delegator; function __construct(AuthService $auth) { $this->delegate($auth, ['authenticate']); } } $auth = new AuthService(); $model = new UserModel($auth); $model->authenticate('test', 'password');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UAPTv
function name:  (null)
number of ops:  13
compiled vars:  !0 = $auth, !1 = $model
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   DECLARE_CLASS                                            'usermodel'
   41     1        NEW                                              $2      'AuthService'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $2
   42     4        NEW                                              $5      'UserModel'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $5
   44     8        INIT_METHOD_CALL                                         !1, 'authenticate'
          9        SEND_VAL_EX                                              'test'
         10        SEND_VAL_EX                                              'password'
         11        DO_FCALL                                      0          
         12      > RETURN                                                   1

Class Delegator:
Function delegate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/UAPTv
function name:  delegate
number of ops:  10
compiled vars:  !0 = $object, !1 = $methods, !2 = $method
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2      > FE_RESET_R                                       $3      !1, ->8
          3    > > FE_FETCH_R                                               $3, !2, ->8
    9     4    >   FETCH_OBJ_W                                      $4      'delegates'
          5        ASSIGN_DIM                                               $4, !2
          6        OP_DATA                                                  !0
    8     7      > JMP                                                      ->3
          8    >   FE_FREE                                                  $3
   11     9      > RETURN                                                   null

End of function delegate

Function __call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/UAPTv
function name:  __call
number of ops:  19
compiled vars:  !0 = $method, !1 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   14     2        FETCH_OBJ_IS                                     ~2      'delegates'
          3        ISSET_ISEMPTY_DIM_OBJ                         0          ~2, !0
          4      > JMPZ                                                     ~3, ->14
   15     5    >   FETCH_OBJ_R                                      ~4      'delegates'
          6        FETCH_DIM_R                                      ~5      ~4, !0
          7        INIT_ARRAY                                       ~6      ~5
          8        ADD_ARRAY_ELEMENT                                ~6      !0
          9        INIT_USER_CALL                                0          'call_user_func_array', ~6
         10        SEND_ARRAY                                               !1
         11        CHECK_UNDEF_ARGS                                         
         12        DO_FCALL                                      0  $7      
         13      > RETURN                                                   $7
   18    14    >   NEW                                              $8      'Exception'
         15        SEND_VAL_EX                                              'Method+not+found%21'
         16        DO_FCALL                                      0          
         17      > THROW                                         0          $8
   19    18*     > RETURN                                                   null

End of function __call

End of class Delegator.

Class AuthService:
Function authenticate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UAPTv
function name:  authenticate
number of ops:  6
compiled vars:  !0 = $username, !1 = $password
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   26     2        CONCAT                                           ~2      'Doing+the+auth+for+', !0
          3        CONCAT                                           ~3      ~2, '%21'
          4        ECHO                                                     ~3
   27     5      > RETURN                                                   null

End of function authenticate

End of class AuthService.

Class UserModel:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UAPTv
function name:  __construct
number of ops:  6
compiled vars:  !0 = $auth
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   36     1        INIT_METHOD_CALL                                         'delegate'
          2        SEND_VAR_EX                                              !0
          3        SEND_VAL_EX                                              <array>
          4        DO_FCALL                                      0          
   37     5      > RETURN                                                   null

End of function __construct

End of class UserModel.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.25 ms | 1399 KiB | 13 Q