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 { public function getInformation($uniqueIdentifier) { $result = $this->cache->get($uniqueIdentifier); if ($result === false) { $result = $this->dataSource->getOne($uniqueIdentifier); $this->cache->set($uniqueIdentifier, $result); } return $result; } } $cachedService = new CachingProxy(new Memcache(), new ImportantService()); $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/T0etc
function name:  (null)
number of ops:  18
compiled vars:  !0 = $cachedService, !1 = $result, !2 = $more
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   NEW                                              $3      'CachingProxy'
          1        NEW                                              $4      'Memcache'
          2        DO_FCALL                                      0          
          3        SEND_VAR_NO_REF_EX                                       $4
          4        NEW                                              $6      'ImportantService'
          5        DO_FCALL                                      0          
          6        SEND_VAR_NO_REF_EX                                       $6
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !0, $3
   48     9        INIT_METHOD_CALL                                         !0, 'getInformation'
         10        SEND_VAL_EX                                              123
         11        DO_FCALL                                      0  $10     
         12        ASSIGN                                                   !1, $10
   49    13        INIT_METHOD_CALL                                         !0, 'getInformation'
         14        SEND_VAL_EX                                              123
         15        DO_FCALL                                      0  $12     
         16        ASSIGN                                                   !2, $12
         17      > RETURN                                                   1

Class CachingProxy:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/T0etc
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/T0etc
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:
Function getinformation:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 18
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/T0etc
function name:  getInformation
number of ops:  20
compiled vars:  !0 = $uniqueIdentifier, !1 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   36     1        FETCH_OBJ_R                                      ~2      'cache'
          2        INIT_METHOD_CALL                                         ~2, 'get'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $3      
          5        ASSIGN                                                   !1, $3
   37     6        TYPE_CHECK                                    4          !1
          7      > JMPZ                                                     ~5, ->18
   38     8    >   FETCH_OBJ_R                                      ~6      'dataSource'
          9        INIT_METHOD_CALL                                         ~6, 'getOne'
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0  $7      
         12        ASSIGN                                                   !1, $7
   39    13        FETCH_OBJ_R                                      ~9      'cache'
         14        INIT_METHOD_CALL                                         ~9, 'set'
         15        SEND_VAR_EX                                              !0
         16        SEND_VAR_EX                                              !1
         17        DO_FCALL                                      0          
   42    18    > > RETURN                                                   !1
   43    19*     > RETURN                                                   null

End of function getinformation

End of class ImportantService.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
178.54 ms | 1404 KiB | 19 Q