3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); namespace Repro; class CycleValue { private ?\stdClass $cycleRef; public function __construct() { // make self cyclically referenced $this->cycleRef = new \stdClass(); $this->cycleRef->x = $this; } public function __destruct() { echo "d\n"; $this->cycleRef->x = null; $this->cycleRef = null; } } class CycleWithDestructorForGcMonitoring { private \Closure $destructorFx; private \stdClass $cycleRef; public function __construct(\Closure $destructorFx) { $this->destructorFx = $destructorFx; $this->cycleRef = new \stdClass(); $this->cycleRef->x = $this; } public function __destruct() { ($this->destructorFx)(); } } $ref = \WeakReference::create(new CycleValue()); $isSecondGcRerun = false; // https://github.com/php/php-src/commit/b58d74547f $createMonitorGcFx = static function () use ($ref): void { $destructorFx = static function () use ($ref): void { echo "gc\n"; var_dump($ref->get() !== null); var_dump($ref->get() !== null); }; new CycleWithDestructorForGcMonitoring($destructorFx); }; $createMonitorGcFx(); gc_collect_cycles(); /**/if (PHP_VERSION_ID < 80100) { gc_collect_cycles(); } echo "done\n";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/mgoqd
function name:  (null)
number of ops:  21
compiled vars:  !0 = $ref, !1 = $isSecondGcRerun, !2 = $createMonitorGcFx
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   INIT_STATIC_METHOD_CALL                                  'WeakReference', 'create'
          1        NEW                                              $3      'Repro%5CCycleValue'
          2        DO_FCALL                                      0          
          3        SEND_VAR                                                 $3
          4        DO_FCALL                                      0  $5      
          5        ASSIGN                                                   !0, $5
   45     6        ASSIGN                                                   !1, <false>
   46     7        DECLARE_LAMBDA_FUNCTION                          ~8      [0]
          8        BIND_LEXICAL                                             ~8, !0
          9        ASSIGN                                                   !2, ~8
   55    10        INIT_DYNAMIC_CALL                                        !2
         11        DO_FCALL                                      0          
   57    12        INIT_NS_FCALL_BY_NAME                                    'Repro%5Cgc_collect_cycles'
         13        DO_FCALL                                      0          
   58    14        FETCH_CONSTANT                                   ~12     'Repro%5CPHP_VERSION_ID'
         15        IS_SMALLER                                               ~12, 80100
         16      > JMPZ                                                     ~13, ->19
         17    >   INIT_NS_FCALL_BY_NAME                                    'Repro%5Cgc_collect_cycles'
         18        DO_FCALL                                      0          
   60    19    >   ECHO                                                     'done%0A'
         20      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mgoqd
function name:  Repro\{closure}
number of ops:  9
compiled vars:  !0 = $ref, !1 = $destructorFx
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   BIND_STATIC                                              !0
   47     1        DECLARE_LAMBDA_FUNCTION                          ~2      [0]
          2        BIND_LEXICAL                                             ~2, !0
          3        ASSIGN                                                   !1, ~2
   53     4        NEW                                              $4      'Repro%5CCycleWithDestructorForGcMonitoring'
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0          
          7        FREE                                                     $4
   54     8      > 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/mgoqd
function name:  Repro\{closure}
number of ops:  15
compiled vars:  !0 = $ref
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   BIND_STATIC                                              !0
   48     1        ECHO                                                     'gc%0A'
   49     2        INIT_NS_FCALL_BY_NAME                                    'Repro%5Cvar_dump'
          3        INIT_METHOD_CALL                                         !0, 'get'
          4        DO_FCALL                                      0  $1      
          5        TYPE_CHECK                                  1020  ~2      $1
          6        SEND_VAL_EX                                              ~2
          7        DO_FCALL                                      0          
   50     8        INIT_NS_FCALL_BY_NAME                                    'Repro%5Cvar_dump'
          9        INIT_METHOD_CALL                                         !0, 'get'
         10        DO_FCALL                                      0  $4      
         11        TYPE_CHECK                                  1020  ~5      $4
         12        SEND_VAL_EX                                              ~5
         13        DO_FCALL                                      0          
   51    14      > RETURN                                                   null

End of Dynamic Function 0

End of Dynamic Function 0

Class Repro\CycleValue:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mgoqd
function name:  __construct
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   NEW                                              $1      'stdClass'
          1        DO_FCALL                                      0          
          2        ASSIGN_OBJ                                               'cycleRef'
          3        OP_DATA                                                  $1
   13     4        FETCH_THIS                                       ~5      
          5        FETCH_OBJ_W                                      $3      'cycleRef'
          6        ASSIGN_OBJ                                               $3, 'x'
          7        OP_DATA                                                  ~5
   14     8      > 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/mgoqd
function name:  __destruct
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   ECHO                                                     'd%0A'
   19     1        FETCH_OBJ_W                                      $0      'cycleRef'
          2        ASSIGN_OBJ                                               $0, 'x'
          3        OP_DATA                                                  null
   20     4        ASSIGN_OBJ                                               'cycleRef'
          5        OP_DATA                                                  null
   21     6      > RETURN                                                   null

End of function __destruct

End of class Repro\CycleValue.

Class Repro\CycleWithDestructorForGcMonitoring:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mgoqd
function name:  __construct
number of ops:  12
compiled vars:  !0 = $destructorFx
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
   32     1        ASSIGN_OBJ                                               'destructorFx'
          2        OP_DATA                                                  !0
   33     3        NEW                                              $3      'stdClass'
          4        DO_FCALL                                      0          
          5        ASSIGN_OBJ                                               'cycleRef'
          6        OP_DATA                                                  $3
   34     7        FETCH_THIS                                       ~7      
          8        FETCH_OBJ_W                                      $5      'cycleRef'
          9        ASSIGN_OBJ                                               $5, 'x'
         10        OP_DATA                                                  ~7
   35    11      > 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/mgoqd
function name:  __destruct
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   FETCH_OBJ_R                                      ~0      'destructorFx'
          1        INIT_DYNAMIC_CALL                                        ~0
          2        DO_FCALL                                      0          
   40     3      > RETURN                                                   null

End of function __destruct

End of class Repro\CycleWithDestructorForGcMonitoring.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.57 ms | 1026 KiB | 15 Q