3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Client { public function getUser(string $userId) { return [ 'id' => 5, ]; } } class Cache { public function set() { var_dump('Called set'); } public function get() { return null; } } class CachedClient { private $callee; private $cache; public function __construct($callee, $cache) { $this->callee = $callee; $this->cache = $cache; } public function __call(string $method, array $attributes) { $key = sprintf($method . '::' . implode(':', $attributes)); $result = $this->cache->get($key); if (!is_null($result)) { return $result; } $result = call_user_func_array([$this->client, $method], $attributes); $this->cache->set($key, $result); return $result; } } $client = new Client(); $cache = new Cache(); $cachedClient = new CachedClient($client, $cache); var_dump($cachedClient->getUser(5));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SQfl8
function name:  (null)
number of ops:  18
compiled vars:  !0 = $client, !1 = $cache, !2 = $cachedClient
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   NEW                                              $3      'Client'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $3
   57     3        NEW                                              $6      'Cache'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $6
   58     6        NEW                                              $9      'CachedClient'
          7        SEND_VAR_EX                                              !0
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !2, $9
   60    11        INIT_FCALL                                               'var_dump'
         12        INIT_METHOD_CALL                                         !2, 'getUser'
         13        SEND_VAL_EX                                              5
         14        DO_FCALL                                      0  $12     
         15        SEND_VAR                                                 $12
         16        DO_ICALL                                                 
         17      > RETURN                                                   1

Class Client:
Function getuser:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SQfl8
function name:  getUser
number of ops:  3
compiled vars:  !0 = $userId
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    8     1      > RETURN                                                   <array>
   10     2*     > RETURN                                                   null

End of function getuser

End of class Client.

Class Cache:
Function set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SQfl8
function name:  set
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   INIT_FCALL                                               'var_dump'
          1        SEND_VAL                                                 'Called+set'
          2        DO_ICALL                                                 
   18     3      > RETURN                                                   null

End of function set

Function get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SQfl8
function name:  get
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E > > RETURN                                                   null
   23     1*     > RETURN                                                   null

End of function get

End of class Cache.

Class CachedClient:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SQfl8
function name:  __construct
number of ops:  7
compiled vars:  !0 = $callee, !1 = $cache
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   34     2        ASSIGN_OBJ                                               'callee'
          3        OP_DATA                                                  !0
   35     4        ASSIGN_OBJ                                               'cache'
          5        OP_DATA                                                  !1
   36     6      > RETURN                                                   null

End of function __construct

Function __call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 21
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SQfl8
function name:  __call
number of ops:  36
compiled vars:  !0 = $method, !1 = $attributes, !2 = $key, !3 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   40     2        INIT_FCALL                                               'sprintf'
          3        CONCAT                                           ~4      !0, '%3A%3A'
          4        INIT_FCALL                                               'implode'
          5        SEND_VAL                                                 '%3A'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $5      
          8        CONCAT                                           ~6      ~4, $5
          9        SEND_VAL                                                 ~6
         10        DO_ICALL                                         $7      
         11        ASSIGN                                                   !2, $7
   42    12        FETCH_OBJ_R                                      ~9      'cache'
         13        INIT_METHOD_CALL                                         ~9, 'get'
         14        SEND_VAR_EX                                              !2
         15        DO_FCALL                                      0  $10     
         16        ASSIGN                                                   !3, $10
   44    17        TYPE_CHECK                                    2  ~12     !3
         18        BOOL_NOT                                         ~13     ~12
         19      > JMPZ                                                     ~13, ->21
   45    20    > > RETURN                                                   !3
   48    21    >   FETCH_OBJ_R                                      ~14     'client'
         22        INIT_ARRAY                                       ~15     ~14
         23        ADD_ARRAY_ELEMENT                                ~15     !0
         24        INIT_USER_CALL                                0          'call_user_func_array', ~15
         25        SEND_ARRAY                                               !1
         26        CHECK_UNDEF_ARGS                                         
         27        DO_FCALL                                      0  $16     
         28        ASSIGN                                                   !3, $16
   50    29        FETCH_OBJ_R                                      ~18     'cache'
         30        INIT_METHOD_CALL                                         ~18, 'set'
         31        SEND_VAR_EX                                              !2
         32        SEND_VAR_EX                                              !3
         33        DO_FCALL                                      0          
   52    34      > RETURN                                                   !3
   53    35*     > RETURN                                                   null

End of function __call

End of class CachedClient.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.48 ms | 1404 KiB | 19 Q