3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { protected $_iterator; protected $_appendIterator; public function __construct($appendIterator = true) { $this->_appendIterator = $appendIterator; $arrayIterator= new ArrayIterator([$this, $this, $this, $this]); if ($appendIterator) { $this->_iterator = new AppendIterator(); $this->_iterator->append($arrayIterator); } else { $this->_iterator = $arrayIterator; } } public function __destruct() { echo 'destructing A::class(' . var_export($this->_appendIterator, true) .') ' . PHP_EOL; } } echo "Running with AppendIterator(): " . PHP_EOL; $mStart = memory_get_usage(); for ($i = 0; $i < 10; $i++) new A(); echo memory_get_usage() - $mStart . " memory increase " . PHP_EOL; echo "Running GC.." . PHP_EOL; echo "Found " . gc_collect_cycles() . " cycles..." . PHP_EOL . PHP_EOL; echo "Running without AppendIterator(): " . PHP_EOL; $mStart = memory_get_usage(); for ($i = 0; $i < 10; $i++) new A(false); echo memory_get_usage() - $mStart . " memory increase " . PHP_EOL; echo "Running GC.." . PHP_EOL; echo "Found " . gc_collect_cycles() . " cycles..." . PHP_EOL; echo "Done!" . PHP_EOL . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 6
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 32
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 32
Branch analysis from position: 39
Branch analysis from position: 32
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 6
Branch analysis from position: 12
Branch analysis from position: 6
filename:       /in/BCI0F
function name:  (null)
number of ops:  54
compiled vars:  !0 = $mStart, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ECHO                                                     'Running+with+AppendIterator%28%29%3A+%0A'
   32     1        INIT_FCALL                                               'memory_get_usage'
          2        DO_ICALL                                         $2      
          3        ASSIGN                                                   !0, $2
   34     4        ASSIGN                                                   !1, 0
          5      > JMP                                                      ->10
   35     6    >   NEW                                              $5      'A'
          7        DO_FCALL                                      0          
          8        FREE                                                     $5
   34     9        PRE_INC                                                  !1
         10    >   IS_SMALLER                                               !1, 10
         11      > JMPNZ                                                    ~8, ->6
   37    12    >   INIT_FCALL                                               'memory_get_usage'
         13        DO_ICALL                                         $9      
         14        SUB                                              ~10     $9, !0
         15        CONCAT                                           ~11     ~10, '+memory+increase+'
         16        CONCAT                                           ~12     ~11, '%0A'
         17        ECHO                                                     ~12
   39    18        ECHO                                                     'Running+GC..%0A'
   41    19        INIT_FCALL                                               'gc_collect_cycles'
         20        DO_ICALL                                         $13     
         21        CONCAT                                           ~14     'Found+', $13
         22        CONCAT                                           ~15     ~14, '+cycles...'
         23        CONCAT                                           ~16     ~15, '%0A'
         24        CONCAT                                           ~17     ~16, '%0A'
         25        ECHO                                                     ~17
   43    26        ECHO                                                     'Running+without+AppendIterator%28%29%3A+%0A'
   45    27        INIT_FCALL                                               'memory_get_usage'
         28        DO_ICALL                                         $18     
         29        ASSIGN                                                   !0, $18
   47    30        ASSIGN                                                   !1, 0
         31      > JMP                                                      ->37
   48    32    >   NEW                                              $21     'A'
         33        SEND_VAL_EX                                              <false>
         34        DO_FCALL                                      0          
         35        FREE                                                     $21
   47    36        PRE_INC                                                  !1
         37    >   IS_SMALLER                                               !1, 10
         38      > JMPNZ                                                    ~24, ->32
   50    39    >   INIT_FCALL                                               'memory_get_usage'
         40        DO_ICALL                                         $25     
         41        SUB                                              ~26     $25, !0
         42        CONCAT                                           ~27     ~26, '+memory+increase+'
         43        CONCAT                                           ~28     ~27, '%0A'
         44        ECHO                                                     ~28
   52    45        ECHO                                                     'Running+GC..%0A'
   54    46        INIT_FCALL                                               'gc_collect_cycles'
         47        DO_ICALL                                         $29     
         48        CONCAT                                           ~30     'Found+', $29
         49        CONCAT                                           ~31     ~30, '+cycles...'
         50        CONCAT                                           ~32     ~31, '%0A'
         51        ECHO                                                     ~32
   56    52        ECHO                                                     'Done%21%0A%0A'
         53      > RETURN                                                   1

Class A:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 25
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BCI0F
function name:  __construct
number of ops:  28
compiled vars:  !0 = $appendIterator, !1 = $arrayIterator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV_INIT                                        !0      <true>
   10     1        ASSIGN_OBJ                                               '_appendIterator'
          2        OP_DATA                                                  !0
   11     3        NEW                                              $3      'ArrayIterator'
          4        FETCH_THIS                                       ~4      
          5        INIT_ARRAY                                       ~5      ~4
          6        FETCH_THIS                                       ~6      
          7        ADD_ARRAY_ELEMENT                                ~5      ~6
          8        FETCH_THIS                                       ~7      
          9        ADD_ARRAY_ELEMENT                                ~5      ~7
         10        FETCH_THIS                                       ~8      
         11        ADD_ARRAY_ELEMENT                                ~5      ~8
         12        SEND_VAL_EX                                              ~5
         13        DO_FCALL                                      0          
         14        ASSIGN                                                   !1, $3
   13    15      > JMPZ                                                     !0, ->25
   15    16    >   NEW                                              $12     'AppendIterator'
         17        DO_FCALL                                      0          
         18        ASSIGN_OBJ                                               '_iterator'
         19        OP_DATA                                                  $12
   16    20        FETCH_OBJ_R                                      ~14     '_iterator'
         21        INIT_METHOD_CALL                                         ~14, 'append'
         22        SEND_VAR_EX                                              !1
         23        DO_FCALL                                      0          
         24      > JMP                                                      ->27
   20    25    >   ASSIGN_OBJ                                               '_iterator'
         26        OP_DATA                                                  !1
   22    27    > > 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/BCI0F
function name:  __destruct
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   INIT_FCALL                                               'var_export'
          1        FETCH_OBJ_R                                      ~0      '_appendIterator'
          2        SEND_VAL                                                 ~0
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $1      
          5        CONCAT                                           ~2      'destructing+A%3A%3Aclass%28', $1
          6        CONCAT                                           ~3      ~2, '%29+'
          7        CONCAT                                           ~4      ~3, '%0A'
          8        ECHO                                                     ~4
   27     9      > RETURN                                                   null

End of function __destruct

End of class A.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.51 ms | 1409 KiB | 19 Q