3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CachingProxy { private $cache = null; private $instance = null; public function __construct(Memcache $cache, $instance) { $this->cache = $cache; $this->instance = $instance; } public function __call($method, $arguments) { var_dump($method, $arguments); die; if (substr($method, 0, 3) !== 'get') { $result = call_user_func_array($method, $arguments); } else { $uniqueId = $method . serialize($arguments); $result = $this->cache->get($uniqueId); if ($result === false) { $result = call_user_func_array($method, $arguments); $this->cache->set($uniqueId, $result); } } return $result; } } class ImportantService { } $service = new ImportantService(); $cachedService = new CachingProxy($memcacheInstance, $service); $result = $cachedService->getInformation(123); // First call goes to a data source $more = $cachedService->getInformation(123); // From cache now
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bDGJJ
function name:  (null)
number of ops:  17
compiled vars:  !0 = $service, !1 = $cachedService, !2 = $memcacheInstance, !3 = $result, !4 = $more
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   NEW                                              $5      'ImportantService'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $5
   37     3        NEW                                              $8      'CachingProxy'
          4        SEND_VAR_EX                                              !2
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $8
   39     8        INIT_METHOD_CALL                                         !1, 'getInformation'
          9        SEND_VAL_EX                                              123
         10        DO_FCALL                                      0  $11     
         11        ASSIGN                                                   !3, $11
   40    12        INIT_METHOD_CALL                                         !1, 'getInformation'
         13        SEND_VAL_EX                                              123
         14        DO_FCALL                                      0  $13     
         15        ASSIGN                                                   !4, $13
         16      > RETURN                                                   1

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

End of function __construct

Function __call:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/bDGJJ
function name:  __call
number of ops:  44
compiled vars:  !0 = $method, !1 = $arguments, !2 = $result, !3 = $uniqueId
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   16     2        INIT_FCALL                                               'var_dump'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                                 
          6      > EXIT                                                     
   17     7*       INIT_FCALL                                               'substr'
          8*       SEND_VAR                                                 !0
          9*       SEND_VAL                                                 0
         10*       SEND_VAL                                                 3
         11*       DO_ICALL                                         $5      
         12*       IS_NOT_IDENTICAL                                         $5, 'get'
         13*       JMPZ                                                     ~6, ->20
   18    14*       INIT_USER_CALL                                0          'call_user_func_array', !0
         15*       SEND_ARRAY                                               !1
         16*       CHECK_UNDEF_ARGS                                         
         17*       DO_FCALL                                      0  $7      
         18*       ASSIGN                                                   !2, $7
         19*       JMP                                                      ->42
   20    20*       INIT_FCALL                                               'serialize'
         21*       SEND_VAR                                                 !1
         22*       DO_ICALL                                         $9      
         23*       CONCAT                                           ~10     !0, $9
         24*       ASSIGN                                                   !3, ~10
   21    25*       FETCH_OBJ_R                                      ~12     'cache'
         26*       INIT_METHOD_CALL                                         ~12, 'get'
         27*       SEND_VAR_EX                                              !3
         28*       DO_FCALL                                      0  $13     
         29*       ASSIGN                                                   !2, $13
   22    30*       TYPE_CHECK                                    4          !2
         31*       JMPZ                                                     ~15, ->42
   23    32*       INIT_USER_CALL                                0          'call_user_func_array', !0
         33*       SEND_ARRAY                                               !1
         34*       CHECK_UNDEF_ARGS                                         
         35*       DO_FCALL                                      0  $16     
         36*       ASSIGN                                                   !2, $16
   24    37*       FETCH_OBJ_R                                      ~18     'cache'
         38*       INIT_METHOD_CALL                                         ~18, 'set'
         39*       SEND_VAR_EX                                              !3
         40*       SEND_VAR_EX                                              !2
         41*       DO_FCALL                                      0          
   28    42*       RETURN                                                   !2
   29    43*     > RETURN                                                   null

End of function __call

End of class CachingProxy.

Class ImportantService: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
180.77 ms | 1405 KiB | 19 Q