3v4l.org

run code in 300+ PHP versions simultaneously
<?php class WeakMap2 { private array $weakRefs = []; private array $values = []; public function offsetSet($object, $value) : void { $id = spl_object_id($object); $this->weakRefs[$id] = \WeakReference::create($object); $this->values[$id] = $value; } } class WeakAnalysingMapRepro { public array $valueWithOwnerCountByIndex = []; private WeakMap2 $ownerDestructorHandlers; public function __construct() { $this->ownerDestructorHandlers = new WeakMap2(); $this->addKeyOwner(new \DateTime()); } protected function addKeyOwner(object $owner) { $handler = new class($this) { private \WeakReference $weakAnalysingMap; public function __construct(WeakAnalysingMapRepro $analysingMap) { $this->weakAnalysingMap = \WeakReference::create($analysingMap); } public function __destruct() { $analysingMap = $this->weakAnalysingMap->get(); var_dump(array_keys($analysingMap->valueWithOwnerCountByIndex)); \Closure::bind(static function () use ($analysingMap) { var_dump(array_keys($analysingMap->valueWithOwnerCountByIndex)); }, null, WeakAnalysingMapRepro::class)(); } public function addReference($index): void { $analysingMap = $this->weakAnalysingMap->get(); $analysingMap->valueWithOwnerCountByIndex[$index] = true; } }; $this->ownerDestructorHandlers->offsetSet($owner, $handler); $handler->addReference(10); } } $map = new WeakAnalysingMapRepro(); unset($map); echo 'DONE';
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/h7ZER
function name:  (null)
number of ops:  6
compiled vars:  !0 = $map
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   NEW                                              $1      'WeakAnalysingMapRepro'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   64     3        UNSET_CV                                                 !0
   66     4        ECHO                                                     'DONE'
          5      > RETURN                                                   1

Class WeakMap2:
Function offsetset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/h7ZER
function name:  offsetSet
number of ops:  16
compiled vars:  !0 = $object, !1 = $value, !2 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   10     2        INIT_FCALL                                               'spl_object_id'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $3      
          5        ASSIGN                                                   !2, $3
   12     6        INIT_STATIC_METHOD_CALL                                  'WeakReference', 'create'
          7        SEND_VAR                                                 !0
          8        DO_FCALL                                      0  $7      
          9        FETCH_OBJ_W                                      $5      'weakRefs'
         10        ASSIGN_DIM                                               $5, !2
         11        OP_DATA                                                  $7
   13    12        FETCH_OBJ_W                                      $8      'values'
         13        ASSIGN_DIM                                               $8, !2
         14        OP_DATA                                                  !1
   14    15      > RETURN                                                   null

End of function offsetset

End of class WeakMap2.

Class class@anonymous:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/h7ZER
function name:  __construct
number of ops:  7
compiled vars:  !0 = $analysingMap
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   37     1        INIT_STATIC_METHOD_CALL                                  'WeakReference', 'create'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $2      
          4        ASSIGN_OBJ                                               'weakAnalysingMap'
          5        OP_DATA                                                  $2
   38     6      > RETURN                                                   null

End of function __construct

Function __destruct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/h7ZER
function name:  __destruct
number of ops:  21
compiled vars:  !0 = $analysingMap
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   FETCH_OBJ_R                                      ~1      'weakAnalysingMap'
          1        INIT_METHOD_CALL                                         ~1, 'get'
          2        DO_FCALL                                      0  $2      
          3        ASSIGN                                                   !0, $2
   44     4        INIT_FCALL                                               'var_dump'
          5        INIT_FCALL                                               'array_keys'
          6        FETCH_OBJ_R                                      ~4      !0, 'valueWithOwnerCountByIndex'
          7        SEND_VAL                                                 ~4
          8        DO_ICALL                                         $5      
          9        SEND_VAR                                                 $5
         10        DO_ICALL                                                 
   45    11        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
         12        DECLARE_LAMBDA_FUNCTION                          ~7      [0]
         13        BIND_LEXICAL                                             ~7, !0
   47    14        SEND_VAL                                                 ~7
         15        SEND_VAL                                                 null
         16        SEND_VAL                                                 'WeakAnalysingMapRepro'
   45    17        DO_FCALL                                      0  $8      
   47    18        INIT_DYNAMIC_CALL                                        $8
         19        DO_FCALL                                      0          
   48    20      > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/h7ZER
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $analysingMap
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   BIND_STATIC                                              !0
   46     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'array_keys'
          3        FETCH_OBJ_R                                      ~1      !0, 'valueWithOwnerCountByIndex'
          4        SEND_VAL                                                 ~1
          5        DO_ICALL                                         $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                                 
   47     8      > RETURN                                                   null

End of Dynamic Function 0

End of function __destruct

Function addreference:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/h7ZER
function name:  addReference
number of ops:  9
compiled vars:  !0 = $index, !1 = $analysingMap
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
   52     1        FETCH_OBJ_R                                      ~2      'weakAnalysingMap'
          2        INIT_METHOD_CALL                                         ~2, 'get'
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !1, $3
   53     5        FETCH_OBJ_W                                      $5      !1, 'valueWithOwnerCountByIndex'
          6        ASSIGN_DIM                                               $5, !0
          7        OP_DATA                                                  <true>
   54     8      > RETURN                                                   null

End of function addreference

End of class class@anonymous.

Class WeakAnalysingMapRepro:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/h7ZER
function name:  __construct
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   NEW                                              $1      'WeakMap2'
          1        DO_FCALL                                      0          
          2        ASSIGN_OBJ                                               'ownerDestructorHandlers'
          3        OP_DATA                                                  $1
   27     4        INIT_METHOD_CALL                                         'addKeyOwner'
          5        NEW                                              $3      'DateTime'
          6        DO_FCALL                                      0          
          7        SEND_VAR_NO_REF_EX                                       $3
          8        DO_FCALL                                      0          
   28     9      > RETURN                                                   null

End of function __construct

Function addkeyowner:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/h7ZER
function name:  addKeyOwner
number of ops:  16
compiled vars:  !0 = $owner, !1 = $handler
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
   32     1        DECLARE_ANON_CLASS                               <unknown> 
          2        NEW                                              $3      $2
          3        FETCH_THIS                                       $4      
          4        SEND_VAR_EX                                              $4
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !1, $3
   57     7        FETCH_OBJ_R                                      ~7      'ownerDestructorHandlers'
          8        INIT_METHOD_CALL                                         ~7, 'offsetSet'
          9        SEND_VAR_EX                                              !0
         10        SEND_VAR_EX                                              !1
         11        DO_FCALL                                      0          
   59    12        INIT_METHOD_CALL                                         !1, 'addReference'
         13        SEND_VAL_EX                                              10
         14        DO_FCALL                                      0          
   60    15      > RETURN                                                   null

End of function addkeyowner

End of class WeakAnalysingMapRepro.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.43 ms | 1009 KiB | 16 Q