3v4l.org

run code in 500+ 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()); $gcRuns = 0; $isSecondGcRerun = false; // https://github.com/php/php-src/commit/b58d74547f $createMonitorGcFx = static function () use (&$createMonitorGcFx, &$gcRuns, &$isSecondGcRerun, $ref): void { $destructorFx = static function () use (&$createMonitorGcFx, &$gcRuns, &$isSecondGcRerun, $ref): void { $gcRunsPrev = $gcRuns; $gcRuns = gc_status()['runs']; if ($gcRunsPrev !== $gcRuns) { // prevent recursion on shutdown echo "gc" . ($isSecondGcRerun ? ' rerun' : '') . "\n"; var_dump($ref->get() !== null); $isSecondGcRerun = !$isSecondGcRerun; $createMonitorGcFx(); } }; new CycleWithDestructorForGcMonitoring($destructorFx); }; $createMonitorGcFx(); gc_collect_cycles(); /**/if (PHP_VERSION_ID < 80100) { gc_collect_cycles(); } var_dump($ref->get() !== null); echo "done\n";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 23
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/USrWu
function name:  (null)
number of ops:  31
compiled vars:  !0 = $ref, !1 = $gcRuns, !2 = $isSecondGcRerun, !3 = $createMonitorGcFx
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   43     0  E >   INIT_STATIC_METHOD_CALL                                      'WeakReference', 'create'
          1        NEW                                                  $4      'Repro%5CCycleValue'
          2        DO_FCALL                                          0          
          3        SEND_VAR                                                     $4
          4        DO_FCALL                                          0  $6      
          5        ASSIGN                                                       !0, $6
   45     6        ASSIGN                                                       !1, 0
   46     7        ASSIGN                                                       !2, <false>
   47     8        DECLARE_LAMBDA_FUNCTION                              ~10     [0]
          9        BIND_LEXICAL                                                 ~10, !3
         10        BIND_LEXICAL                                                 ~10, !1
         11        BIND_LEXICAL                                                 ~10, !2
         12        BIND_LEXICAL                                                 ~10, !0
         13        ASSIGN                                                       !3, ~10
   61    14        INIT_DYNAMIC_CALL                                            !3
         15        DO_FCALL                                          0          
   63    16        INIT_NS_FCALL_BY_NAME                                        'Repro%5Cgc_collect_cycles'
         17        DO_FCALL                                          0          
   64    18        FETCH_CONSTANT                                       ~14     'Repro%5CPHP_VERSION_ID'
         19        IS_SMALLER                                                   ~14, 80100
         20      > JMPZ                                                         ~15, ->23
         21    >   INIT_NS_FCALL_BY_NAME                                        'Repro%5Cgc_collect_cycles'
         22        DO_FCALL                                          0          
   66    23    >   INIT_NS_FCALL_BY_NAME                                        'Repro%5Cvar_dump'
         24        INIT_METHOD_CALL                                             !0, 'get'
         25        DO_FCALL                                          0  $17     
         26        TYPE_CHECK                                      1020  ~18     $17
         27        SEND_VAL_EX                                                  ~18
         28        DO_FCALL                                          0          
   68    29        ECHO                                                         'done%0A'
         30      > 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/USrWu
function name:  {closure:/in/USrWu:47}
number of ops:  15
compiled vars:  !0 = $createMonitorGcFx, !1 = $gcRuns, !2 = $isSecondGcRerun, !3 = $ref, !4 = $destructorFx
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   47     0  E >   BIND_STATIC                                                  !0
          1        BIND_STATIC                                                  !1
          2        BIND_STATIC                                                  !2
          3        BIND_STATIC                                                  !3
   48     4        DECLARE_LAMBDA_FUNCTION                              ~5      [0]
          5        BIND_LEXICAL                                                 ~5, !0
          6        BIND_LEXICAL                                                 ~5, !1
          7        BIND_LEXICAL                                                 ~5, !2
          8        BIND_LEXICAL                                                 ~5, !3
          9        ASSIGN                                                       !4, ~5
   59    10        NEW                                                  $7      'Repro%5CCycleWithDestructorForGcMonitoring'
         11        SEND_VAR_EX                                                  !4
         12        DO_FCALL                                          0          
         13        FREE                                                         $7
   60    14      > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 28
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/USrWu
function name:  {closure:{closure:/in/USrWu:47}:48}
number of ops:  29
compiled vars:  !0 = $createMonitorGcFx, !1 = $gcRuns, !2 = $isSecondGcRerun, !3 = $ref, !4 = $gcRunsPrev
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   48     0  E >   BIND_STATIC                                                  !0
          1        BIND_STATIC                                                  !1
          2        BIND_STATIC                                                  !2
          3        BIND_STATIC                                                  !3
   49     4        ASSIGN                                                       !4, !1
   50     5        INIT_NS_FCALL_BY_NAME                                        'Repro%5Cgc_status'
          6        DO_FCALL                                          0  $6      
          7        FETCH_DIM_R                                          ~7      $6, 'runs'
          8        ASSIGN                                                       !1, ~7
   51     9        IS_NOT_IDENTICAL                                             !4, !1
         10      > JMPZ                                                         ~9, ->28
   52    11    > > JMPZ                                                         !2, ->14
         12    >   QM_ASSIGN                                            ~10     '+rerun'
         13      > JMP                                                          ->15
         14    >   QM_ASSIGN                                            ~10     ''
         15    >   CONCAT                                               ~11     'gc', ~10
         16        CONCAT                                               ~12     ~11, '%0A'
         17        ECHO                                                         ~12
   53    18        INIT_NS_FCALL_BY_NAME                                        'Repro%5Cvar_dump'
         19        INIT_METHOD_CALL                                             !3, 'get'
         20        DO_FCALL                                          0  $13     
         21        TYPE_CHECK                                      1020  ~14     $13
         22        SEND_VAL_EX                                                  ~14
         23        DO_FCALL                                          0          
   54    24        BOOL_NOT                                             ~16     !2
         25        ASSIGN                                                       !2, ~16
   55    26        INIT_DYNAMIC_CALL                                            !0
         27        DO_FCALL                                          0          
   57    28    > > 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/USrWu
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/USrWu
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/USrWu
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/USrWu
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.5.0


preferences:
155.34 ms | 2788 KiB | 11 Q