3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Memcache { private $data = []; public function set($key, $value) { $this->data[$key] = $value; } public function get($key) { return isset($this->data[$key]) ? $this->data[$key] : false; } } 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/FFsBp
function name:  (null)
number of ops:  18
compiled vars:  !0 = $cachedService, !1 = $result, !2 = $more
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     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
   60     9        INIT_METHOD_CALL                                         !0, 'getInformation'
         10        SEND_VAL_EX                                              123
         11        DO_FCALL                                      0  $10     
         12        ASSIGN                                                   !1, $10
   61    13        INIT_METHOD_CALL                                         !0, 'getInformation'
         14        SEND_VAL_EX                                              123
         15        DO_FCALL                                      0  $12     
         16        ASSIGN                                                   !2, $12
         17      > RETURN                                                   1

Class Memcache:
Function set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FFsBp
function name:  set
number of ops:  6
compiled vars:  !0 = $key, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        FETCH_OBJ_W                                      $2      'data'
          3        ASSIGN_DIM                                               $2, !0
          4        OP_DATA                                                  !1
    8     5      > RETURN                                                   null

End of function set

Function get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FFsBp
function name:  get
number of ops:  11
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   11     1        FETCH_OBJ_IS                                     ~1      'data'
          2        ISSET_ISEMPTY_DIM_OBJ                         0          ~1, !0
          3      > JMPZ                                                     ~2, ->8
          4    >   FETCH_OBJ_R                                      ~3      'data'
          5        FETCH_DIM_R                                      ~4      ~3, !0
          6        QM_ASSIGN                                        ~5      ~4
          7      > JMP                                                      ->9
          8    >   QM_ASSIGN                                        ~5      <false>
          9    > > RETURN                                                   ~5
   12    10*     > RETURN                                                   null

End of function get

End of class Memcache.

Class CachingProxy:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FFsBp
function name:  __construct
number of ops:  7
compiled vars:  !0 = $cache, !1 = $instance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   22     2        ASSIGN_OBJ                                               'cache'
          3        OP_DATA                                                  !0
   23     4        ASSIGN_OBJ                                               'instance'
          5        OP_DATA                                                  !1
   24     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/FFsBp
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
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   28     2        INIT_FCALL                                               'var_dump'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                                 
          6      > EXIT                                                     
   29     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
   30    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
   32    20*       INIT_FCALL                                               'serialize'
         21*       SEND_VAR                                                 !1
         22*       DO_ICALL                                         $9      
         23*       CONCAT                                           ~10     !0, $9
         24*       ASSIGN                                                   !3, ~10
   33    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
   34    30*       TYPE_CHECK                                    4          !2
         31*       JMPZ                                                     ~15, ->42
   35    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
   36    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          
   40    42*       RETURN                                                   !2
   41    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/FFsBp
function name:  getInformation
number of ops:  20
compiled vars:  !0 = $uniqueIdentifier, !1 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
   48     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
   49     6        TYPE_CHECK                                    4          !1
          7      > JMPZ                                                     ~5, ->18
   50     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
   51    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          
   54    18    > > RETURN                                                   !1
   55    19*     > RETURN                                                   null

End of function getinformation

End of class ImportantService.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.4 ms | 1396 KiB | 19 Q