3v4l.org

run code in 500+ PHP versions simultaneously
<?php class MemoryCache { protected $data = []; public function set($key, $value) { $this->data[$key] = $value; } public function get($key) { return $this->data[$key] ?? NULL; } } class InternalReferenceCycleVoodooMemoryCacheWrapper { protected $memoryCache; protected $cycle; public function __construct(MemoryCache $memoryCache) { $this->memoryCache = $memoryCache; $this->cycle = $this; } public function unwrap() { return $this->memoryCache; } } class GarbageCollectableMemoryCacheDecorator { protected $memoryCacheWrapperWeakref; protected function createWrapper(): InternalReferenceCycleVoodooMemoryCacheWrapper { return new InternalReferenceCycleVoodooMemoryCacheWrapper(new MemoryCache()); } protected function initWeakref(): WeakReference { return $this->memoryCacheWrapperWeakref = WeakReference::create($this->createWrapper()); } protected function getMemoryCache() { $weakref = $this->memoryCacheWrapperWeakref ?? $this->initWeakref(); $wrapper = $weakref->get() ?? $this->initWeakref()->get(); return $wrapper->unwrap(); } public function set($key, $value) { $this->getMemoryCache()->set($key, $value); } public function get($key) { return $this->getMemoryCache()->get($key); } } $mc = new GarbageCollectableMemoryCacheDecorator(); $mc->set('foo', 'bar'); printf("Data value after set: %s\n", print_r($mc->get('foo'), 1)); gc_collect_cycles(); printf("Data value after GC: %s\n", print_r($mc->get('foo'), 1)); $mc->set('foo', 'baz'); printf("Data value after set: %s\n", print_r($mc->get('foo'), 1)); gc_collect_cycles(); printf("Data value after GC: %s\n", print_r($mc->get('foo'), 1));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MG8tb
function name:  (null)
number of ops:  60
compiled vars:  !0 = $mc
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   62     0  E >   NEW                                                  $1      'GarbageCollectableMemoryCacheDecorator'
          1        DO_FCALL                                          0          
          2        ASSIGN                                                       !0, $1
   63     3        INIT_METHOD_CALL                                             !0, 'set'
          4        SEND_VAL_EX                                                  'foo'
          5        SEND_VAL_EX                                                  'bar'
          6        DO_FCALL                                          0          
   64     7        INIT_FCALL                                                   'printf'
          8        SEND_VAL                                                     'Data+value+after+set%3A+%25s%0A'
          9        INIT_FCALL                                                   'print_r'
         10        INIT_METHOD_CALL                                             !0, 'get'
         11        SEND_VAL_EX                                                  'foo'
         12        DO_FCALL                                          0  $5      
         13        SEND_VAR                                                     $5
         14        SEND_VAL                                                     1
         15        DO_ICALL                                             $6      
         16        SEND_VAR                                                     $6
         17        DO_ICALL                                                     
   65    18        INIT_FCALL                                                   'gc_collect_cycles'
         19        DO_ICALL                                                     
   66    20        INIT_FCALL                                                   'printf'
         21        SEND_VAL                                                     'Data+value+after+GC%3A+%25s%0A'
         22        INIT_FCALL                                                   'print_r'
         23        INIT_METHOD_CALL                                             !0, 'get'
         24        SEND_VAL_EX                                                  'foo'
         25        DO_FCALL                                          0  $9      
         26        SEND_VAR                                                     $9
         27        SEND_VAL                                                     1
         28        DO_ICALL                                             $10     
         29        SEND_VAR                                                     $10
         30        DO_ICALL                                                     
   68    31        INIT_METHOD_CALL                                             !0, 'set'
         32        SEND_VAL_EX                                                  'foo'
         33        SEND_VAL_EX                                                  'baz'
         34        DO_FCALL                                          0          
   69    35        INIT_FCALL                                                   'printf'
         36        SEND_VAL                                                     'Data+value+after+set%3A+%25s%0A'
         37        INIT_FCALL                                                   'print_r'
         38        INIT_METHOD_CALL                                             !0, 'get'
         39        SEND_VAL_EX                                                  'foo'
         40        DO_FCALL                                          0  $13     
         41        SEND_VAR                                                     $13
         42        SEND_VAL                                                     1
         43        DO_ICALL                                             $14     
         44        SEND_VAR                                                     $14
         45        DO_ICALL                                                     
   70    46        INIT_FCALL                                                   'gc_collect_cycles'
         47        DO_ICALL                                                     
   71    48        INIT_FCALL                                                   'printf'
         49        SEND_VAL                                                     'Data+value+after+GC%3A+%25s%0A'
         50        INIT_FCALL                                                   'print_r'
         51        INIT_METHOD_CALL                                             !0, 'get'
         52        SEND_VAL_EX                                                  'foo'
         53        DO_FCALL                                          0  $17     
         54        SEND_VAR                                                     $17
         55        SEND_VAL                                                     1
         56        DO_ICALL                                             $18     
         57        SEND_VAR                                                     $18
         58        DO_ICALL                                                     
         59      > RETURN                                                       1

Class MemoryCache:
Function set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MG8tb
function name:  set
number of ops:  6
compiled vars:  !0 = $key, !1 = $value
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
    8     2        FETCH_OBJ_W                                          $2      'data'
          3        ASSIGN_DIM                                                   $2, !0
          4        OP_DATA                                                      !1
    9     5      > 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/MG8tb
function name:  get
number of ops:  7
compiled vars:  !0 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   11     0  E >   RECV                                                 !0      
   12     1        FETCH_OBJ_IS                                         ~1      'data'
          2        FETCH_DIM_IS                                         ~2      ~1, !0
          3        COALESCE                                             ~3      ~2
          4        QM_ASSIGN                                            ~3      null
          5      > RETURN                                                       ~3
   13     6*     > RETURN                                                       null

End of function get

End of class MemoryCache.

Class InternalReferenceCycleVoodooMemoryCacheWrapper:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MG8tb
function name:  __construct
number of ops:  7
compiled vars:  !0 = $memoryCache
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   23     0  E >   RECV                                                 !0      
   24     1        ASSIGN_OBJ                                                   'memoryCache'
          2        OP_DATA                                                      !0
   25     3        FETCH_THIS                                           ~3      
          4        ASSIGN_OBJ                                                   'cycle'
          5        OP_DATA                                                      ~3
   26     6      > RETURN                                                       null

End of function __construct

Function unwrap:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MG8tb
function name:  unwrap
number of ops:  3
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   29     0  E >   FETCH_OBJ_R                                          ~0      'memoryCache'
          1      > RETURN                                                       ~0
   30     2*     > RETURN                                                       null

End of function unwrap

End of class InternalReferenceCycleVoodooMemoryCacheWrapper.

Class GarbageCollectableMemoryCacheDecorator:
Function createwrapper:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MG8tb
function name:  createWrapper
number of ops:  9
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   39     0  E >   NEW                                                  $0      'InternalReferenceCycleVoodooMemoryCacheWrapper'
          1        NEW                                                  $1      'MemoryCache'
          2        DO_FCALL                                          0          
          3        SEND_VAR_NO_REF_EX                                           $1
          4        DO_FCALL                                          0          
          5        VERIFY_RETURN_TYPE                                           $0
          6      > RETURN                                                       $0
   40     7*       VERIFY_RETURN_TYPE                                           
          8*     > RETURN                                                       null

End of function createwrapper

Function initweakref:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MG8tb
function name:  initWeakref
number of ops:  11
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   43     0  E >   INIT_STATIC_METHOD_CALL                                      'WeakReference', 'create'
          1        INIT_METHOD_CALL                                             'createWrapper'
          2        DO_FCALL                                          0  $1      
          3        SEND_VAR                                                     $1
          4        DO_FCALL                                          0  $2      
          5        ASSIGN_OBJ                                           ~0      'memoryCacheWrapperWeakref'
          6        OP_DATA                                                      $2
          7        VERIFY_RETURN_TYPE                                           ~0
          8      > RETURN                                                       ~0
   44     9*       VERIFY_RETURN_TYPE                                           
         10*     > RETURN                                                       null

End of function initweakref

Function getmemorycache:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MG8tb
function name:  getMemoryCache
number of ops:  19
compiled vars:  !0 = $weakref, !1 = $wrapper
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   47     0  E >   FETCH_OBJ_IS                                         ~2      'memoryCacheWrapperWeakref'
          1        COALESCE                                             ~3      ~2
          2        INIT_METHOD_CALL                                             'initWeakref'
          3        DO_FCALL                                          0  $4      
          4        QM_ASSIGN                                            ~3      $4
          5        ASSIGN                                                       !0, ~3
   48     6        INIT_METHOD_CALL                                             !0, 'get'
          7        DO_FCALL                                          0  $6      
          8        COALESCE                                             ~7      $6
          9        INIT_METHOD_CALL                                             'initWeakref'
         10        DO_FCALL                                          0  $8      
         11        INIT_METHOD_CALL                                             $8, 'get'
         12        DO_FCALL                                          0  $9      
         13        QM_ASSIGN                                            ~7      $9
         14        ASSIGN                                                       !1, ~7
   49    15        INIT_METHOD_CALL                                             !1, 'unwrap'
         16        DO_FCALL                                          0  $11     
         17      > RETURN                                                       $11
   50    18*     > RETURN                                                       null

End of function getmemorycache

Function set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MG8tb
function name:  set
number of ops:  9
compiled vars:  !0 = $key, !1 = $value
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   52     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   53     2        INIT_METHOD_CALL                                             'getMemoryCache'
          3        DO_FCALL                                          0  $2      
          4        INIT_METHOD_CALL                                             $2, 'set'
          5        SEND_VAR_EX                                                  !0
          6        SEND_VAR_EX                                                  !1
          7        DO_FCALL                                          0          
   54     8      > 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/MG8tb
function name:  get
number of ops:  8
compiled vars:  !0 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   56     0  E >   RECV                                                 !0      
   57     1        INIT_METHOD_CALL                                             'getMemoryCache'
          2        DO_FCALL                                          0  $1      
          3        INIT_METHOD_CALL                                             $1, 'get'
          4        SEND_VAR_EX                                                  !0
          5        DO_FCALL                                          0  $2      
          6      > RETURN                                                       $2
   58     7*     > RETURN                                                       null

End of function get

End of class GarbageCollectableMemoryCacheDecorator.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
150.35 ms | 1470 KiB | 11 Q