3v4l.org

run code in 300+ PHP versions simultaneously
<?php class WrappingIterator implements \Iterator { private $index; private $iterator; public function __construct(int $index, Traversable $traversable) { printf('Creating %s %d' . PHP_EOL, static::class, $index); $this->index = $index; $this->iterator = $this->wrapTraversable($traversable); } public function __destruct() { printf('Destroying %s %d' . PHP_EOL, static::class, $this->index); } protected function destroyWrappedIterator() { $this->iterator = null; } public function current() { return $this->iterator->current(); } public function next() { $this->iterator->next(); } public function key() { return $this->iterator->key(); } public function valid() { return $this->iterator->valid(); } public function rewind() { $this->iterator->rewind(); } private function wrapTraversable(Traversable $traversable) { foreach ($traversable as $key => $value) { yield $key => $value; } } } class DestroyingIterator extends WrappingIterator { public function __destruct() { parent::__destruct(); $this->destroyWrappedIterator(); } } class WrappedIterator extends ArrayIterator { public function __construct(int $index) { parent::__construct([1, 2, 3, 4]); $this->index = $index; } public function __destruct() { printf('Destroying WrappedIterator %d' . PHP_EOL, $this->index); } } function testIterator(string $class, int $limit = 20) { printf('Starting run with class "%s" and limit "%d"' . PHP_EOL, $class, $limit); gc_enable(); gc_collect_cycles(); for ($i = 1; $i <= $limit; $i++) { $iterator = new $class($i, new WrappedIterator($i)); $iterator->current(); if ($i % 5 === 0) { gc_collect_cycles(); } } gc_collect_cycles(); echo 'Done', PHP_EOL; } testIterator(WrappingIterator::class); testIterator(DestroyingIterator::class);

Abusive script

This script was stopped while abusing our resources

Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UIfIb
function name:  (null)
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'wrappingiterator'
   58     1        DECLARE_CLASS                                            'destroyingiterator', 'wrappingiterator'
  103     2        INIT_FCALL                                               'testiterator'
          3        SEND_VAL                                                 'WrappingIterator'
          4        DO_FCALL                                      0          
  104     5        INIT_FCALL                                               'testiterator'
          6        SEND_VAL                                                 'DestroyingIterator'
          7        DO_FCALL                                      0          
          8      > RETURN                                                   1

Function testiterator:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 13
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 29
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 13
Branch analysis from position: 32
Branch analysis from position: 13
Branch analysis from position: 29
filename:       /in/UIfIb
function name:  testIterator
number of ops:  37
compiled vars:  !0 = $class, !1 = $limit, !2 = $i, !3 = $iterator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   82     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      20
   84     2        INIT_FCALL                                               'printf'
          3        SEND_VAL                                                 'Starting+run+with+class+%22%25s%22+and+limit+%22%25d%22%0A'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                                 
   86     7        INIT_FCALL                                               'gc_enable'
          8        DO_ICALL                                                 
   87     9        INIT_FCALL                                               'gc_collect_cycles'
         10        DO_ICALL                                                 
   89    11        ASSIGN                                                   !2, 1
         12      > JMP                                                      ->30
   90    13    >   FETCH_CLASS                                   0  $8      !0
         14        NEW                                              $9      $8
         15        SEND_VAR_EX                                              !2
         16        NEW                                              $10     'WrappedIterator'
         17        SEND_VAR_EX                                              !2
         18        DO_FCALL                                      0          
         19        SEND_VAR_NO_REF_EX                                       $10
         20        DO_FCALL                                      0          
         21        ASSIGN                                                   !3, $9
   91    22        INIT_METHOD_CALL                                         !3, 'current'
         23        DO_FCALL                                      0          
   93    24        MOD                                              ~15     !2, 5
         25        IS_IDENTICAL                                             ~15, 0
         26      > JMPZ                                                     ~16, ->29
   94    27    >   INIT_FCALL                                               'gc_collect_cycles'
         28        DO_ICALL                                                 
   89    29    >   PRE_INC                                                  !2
         30    >   IS_SMALLER_OR_EQUAL                                      !2, !1
         31      > JMPNZ                                                    ~19, ->13
   98    32    >   INIT_FCALL                                               'gc_collect_cycles'
         33        DO_ICALL                                                 
  100    34        ECHO                                                     'Done'
         35        ECHO                                                     '%0A'
  101    36      > RETURN                                                   null

End of function testiterator

Class WrappingIterator:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UIfIb
function name:  __construct
number of ops:  16
compiled vars:  !0 = $index, !1 = $traversable
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   10     2        INIT_FCALL                                               'printf'
          3        SEND_VAL                                                 'Creating+%25s+%25d%0A'
          4        FETCH_CLASS_NAME                                 ~2      
          5        SEND_VAL                                                 ~2
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                                 
   11     8        ASSIGN_OBJ                                               'index'
          9        OP_DATA                                                  !0
   12    10        INIT_METHOD_CALL                                         'wrapTraversable'
         11        SEND_VAR_EX                                              !1
         12        DO_FCALL                                      0  $6      
         13        ASSIGN_OBJ                                               'iterator'
         14        OP_DATA                                                  $6
   13    15      > 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/UIfIb
function name:  __destruct
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   INIT_FCALL                                               'printf'
          1        SEND_VAL                                                 'Destroying+%25s+%25d%0A'
          2        FETCH_CLASS_NAME                                 ~0      
          3        SEND_VAL                                                 ~0
          4        FETCH_OBJ_R                                      ~1      'index'
          5        SEND_VAL                                                 ~1
          6        DO_ICALL                                                 
   18     7      > RETURN                                                   null

End of function __destruct

Function destroywrappediterator:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UIfIb
function name:  destroyWrappedIterator
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   ASSIGN_OBJ                                               'iterator'
          1        OP_DATA                                                  null
   23     2      > RETURN                                                   null

End of function destroywrappediterator

Function current:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UIfIb
function name:  current
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   FETCH_OBJ_R                                      ~0      'iterator'
          1        INIT_METHOD_CALL                                         ~0, 'current'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   28     4*     > RETURN                                                   null

End of function current

Function next:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UIfIb
function name:  next
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   FETCH_OBJ_R                                      ~0      'iterator'
          1        INIT_METHOD_CALL                                         ~0, 'next'
          2        DO_FCALL                                      0          
   33     3      > RETURN                                                   null

End of function next

Function key:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UIfIb
function name:  key
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   FETCH_OBJ_R                                      ~0      'iterator'
          1        INIT_METHOD_CALL                                         ~0, 'key'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   38     4*     > RETURN                                                   null

End of function key

Function valid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UIfIb
function name:  valid
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   FETCH_OBJ_R                                      ~0      'iterator'
          1        INIT_METHOD_CALL                                         ~0, 'valid'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   43     4*     > RETURN                                                   null

End of function valid

Function rewind:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UIfIb
function name:  rewind
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   FETCH_OBJ_R                                      ~0      'iterator'
          1        INIT_METHOD_CALL                                         ~0, 'rewind'
          2        DO_FCALL                                      0          
   48     3      > RETURN                                                   null

End of function rewind

Function wraptraversable:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 7
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 7
filename:       /in/UIfIb
function name:  wrapTraversable
number of ops:  9
compiled vars:  !0 = $traversable, !1 = $value, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   52     2      > FE_RESET_R                                       $3      !0, ->7
          3    > > FE_FETCH_R                                       ~4      $3, !1, ->7
          4    >   ASSIGN                                                   !2, ~4
   53     5        YIELD                                                    !1, !2
   52     6      > JMP                                                      ->3
          7    >   FE_FREE                                                  $3
   55     8      > GENERATOR_RETURN                                         

End of function wraptraversable

End of class WrappingIterator.

Class DestroyingIterator:
Function __destruct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UIfIb
function name:  __destruct
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   INIT_STATIC_METHOD_CALL                                  '__destruct'
          1        DO_FCALL                                      0          
   63     2        INIT_METHOD_CALL                                         'destroyWrappedIterator'
          3        DO_FCALL                                      0          
   64     4      > RETURN                                                   null

End of function __destruct

End of class DestroyingIterator.

Class WrappedIterator:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UIfIb
function name:  __construct
number of ops:  7
compiled vars:  !0 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   RECV                                             !0      
   71     1        INIT_STATIC_METHOD_CALL                                  
          2        SEND_VAL_EX                                              <array>
          3        DO_FCALL                                      0          
   73     4        ASSIGN_OBJ                                               'index'
          5        OP_DATA                                                  !0
   74     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/UIfIb
function name:  __destruct
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   78     0  E >   INIT_FCALL                                               'printf'
          1        SEND_VAL                                                 'Destroying+WrappedIterator+%25d%0A'
          2        FETCH_OBJ_R                                      ~0      'index'
          3        SEND_VAL                                                 ~0
          4        DO_ICALL                                                 
   79     5      > RETURN                                                   null

End of function __destruct

End of class WrappedIterator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
128.09 ms | 1032 KiB | 18 Q