3v4l.org

run code in 300+ PHP versions simultaneously
<?php header("Content-type: text/plain"); class Foo { /** * An indentifier * @var string */ private $name; /** * A reference to another Foo object * @var Foo */ private $link; public function __construct($name) { $this->name = $name; } public function setLink(Foo $link){ $this->link = $link; } public function __destruct() { echo 'Destroying: ', $this->name, PHP_EOL; unset( $this->link ); } } // create two Foo objects: $foo = new Foo('Foo 1'); $bar = new Foo('Foo 2'); // make them point to each other $foo->setLink($bar); $bar->setLink($foo); // destroy the global references to them unset( $bar ); $foo = null; $bar = null; // we now have no way to access Foo 1 or Foo 2, so they OUGHT to be __destruct()ed // but they are not, so we get a memory leak as they are still in memory. // // Uncomment the next line to see the difference when explicitly calling the GC: //gc_collect_cycles(); // // see also: http://www.php.net/manual/en/features.gc.php // // create two more Foo objects, but DO NOT set their internal Foo references // so nothing except the vars $foo and $bar point to them: $foo = new Foo('Foo 3'); $bar = new Foo('Foo 4'); // destroy the global references to them $foo = null; $bar = null; // we now have no way to access Foo 3 or Foo 4 and as there are no more references // to them anywhere, their __destruct() methods are automatically called here, // BEFORE the next line is executed: echo 'End of script', PHP_EOL; ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pDtTA
function name:  (null)
number of ops:  33
compiled vars:  !0 = $foo, !1 = $bar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'header'
          1        SEND_VAL                                                 'Content-type%3A+text%2Fplain'
          2        DO_ICALL                                                 
   33     3        NEW                                              $3      'Foo'
          4        SEND_VAL_EX                                              'Foo+1'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $3
   34     7        NEW                                              $6      'Foo'
          8        SEND_VAL_EX                                              'Foo+2'
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !1, $6
   37    11        INIT_METHOD_CALL                                         !0, 'setLink'
         12        SEND_VAR_EX                                              !1
         13        DO_FCALL                                      0          
   38    14        INIT_METHOD_CALL                                         !1, 'setLink'
         15        SEND_VAR_EX                                              !0
         16        DO_FCALL                                      0          
   41    17        UNSET_CV                                                 !1
   42    18        ASSIGN                                                   !0, null
   43    19        ASSIGN                                                   !1, null
   56    20        NEW                                              $13     'Foo'
         21        SEND_VAL_EX                                              'Foo+3'
         22        DO_FCALL                                      0          
         23        ASSIGN                                                   !0, $13
   57    24        NEW                                              $16     'Foo'
         25        SEND_VAL_EX                                              'Foo+4'
         26        DO_FCALL                                      0          
         27        ASSIGN                                                   !1, $16
   60    28        ASSIGN                                                   !0, null
   61    29        ASSIGN                                                   !1, null
   67    30        ECHO                                                     'End+of+script'
         31        ECHO                                                     '%0A'
   69    32      > RETURN                                                   1

Class Foo:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pDtTA
function name:  __construct
number of ops:  4
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   19     1        ASSIGN_OBJ                                               'name'
          2        OP_DATA                                                  !0
   20     3      > RETURN                                                   null

End of function __construct

Function setlink:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pDtTA
function name:  setLink
number of ops:  4
compiled vars:  !0 = $link
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   23     1        ASSIGN_OBJ                                               'link'
          2        OP_DATA                                                  !0
   24     3      > RETURN                                                   null

End of function setlink

Function __destruct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pDtTA
function name:  __destruct
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   ECHO                                                     'Destroying%3A+'
          1        FETCH_OBJ_R                                      ~0      'name'
          2        ECHO                                                     ~0
          3        ECHO                                                     '%0A'
   28     4        UNSET_OBJ                                                'link'
   29     5      > RETURN                                                   null

End of function __destruct

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.84 ms | 1400 KiB | 15 Q