3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Action { /** @var \Iterator */ public $generator; public function __construct(array $data) { $this->generator = new class($this, $data) extends \ArrayIterator { /** @var Action */ public $action; public function __construct(Action $action, array $data) { $this->action = $action; // circular ref (can be any custom iterator) parent::__construct($data); } }; echo '-- c ' . spl_object_id($this) . "\n"; } public function __destruct() { echo '-- d ' . spl_object_id($this) . "\n"; } /** * @return $this */ public function filter() { $filterFx = function ($row) { return $row !== $this; // always true, dummy use $this }; $this->generator = new \CallbackFilterIterator($this->generator, $filterFx); $this->generator->rewind(); return $this; } /** * @return $this */ public function limit(int $limit = null, int $offset = 0) { $this->generator = new \LimitIterator($this->generator, $offset, $limit ?? -1); $this->generator->rewind(); return $this; } } $action = new Action(['a', 'b']); print_r(iterator_to_array($action->generator)); $action = null; gc_collect_cycles(); $action = new Action(['a', 'b']); $action->filter(); print_r(iterator_to_array($action->generator)); $action = null; gc_collect_cycles(); $action = new Action(['a', 'b']); $action->filter()->limit(1); print_r(iterator_to_array($action->generator)); $action = null; gc_collect_cycles(); echo '----------------' . "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YQIVJ
function name:  (null)
number of ops:  51
compiled vars:  !0 = $action
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   NEW                                              $1      'Action'
          1        SEND_VAL_EX                                              <array>
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   58     4        INIT_FCALL                                               'print_r'
          5        INIT_FCALL                                               'iterator_to_array'
          6        FETCH_OBJ_R                                      ~4      !0, 'generator'
          7        SEND_VAL                                                 ~4
          8        DO_ICALL                                         $5      
          9        SEND_VAR                                                 $5
         10        DO_ICALL                                                 
   59    11        ASSIGN                                                   !0, null
         12        INIT_FCALL                                               'gc_collect_cycles'
         13        DO_ICALL                                                 
   61    14        NEW                                              $9      'Action'
         15        SEND_VAL_EX                                              <array>
         16        DO_FCALL                                      0          
         17        ASSIGN                                                   !0, $9
   62    18        INIT_METHOD_CALL                                         !0, 'filter'
         19        DO_FCALL                                      0          
   63    20        INIT_FCALL                                               'print_r'
         21        INIT_FCALL                                               'iterator_to_array'
         22        FETCH_OBJ_R                                      ~13     !0, 'generator'
         23        SEND_VAL                                                 ~13
         24        DO_ICALL                                         $14     
         25        SEND_VAR                                                 $14
         26        DO_ICALL                                                 
   64    27        ASSIGN                                                   !0, null
         28        INIT_FCALL                                               'gc_collect_cycles'
         29        DO_ICALL                                                 
   66    30        NEW                                              $18     'Action'
         31        SEND_VAL_EX                                              <array>
         32        DO_FCALL                                      0          
         33        ASSIGN                                                   !0, $18
   67    34        INIT_METHOD_CALL                                         !0, 'filter'
         35        DO_FCALL                                      0  $21     
         36        INIT_METHOD_CALL                                         $21, 'limit'
         37        SEND_VAL_EX                                              1
         38        DO_FCALL                                      0          
   68    39        INIT_FCALL                                               'print_r'
         40        INIT_FCALL                                               'iterator_to_array'
         41        FETCH_OBJ_R                                      ~23     !0, 'generator'
         42        SEND_VAL                                                 ~23
         43        DO_ICALL                                         $24     
         44        SEND_VAR                                                 $24
         45        DO_ICALL                                                 
   69    46        ASSIGN                                                   !0, null
         47        INIT_FCALL                                               'gc_collect_cycles'
         48        DO_ICALL                                                 
   71    49        ECHO                                                     '----------------%0A'
         50      > RETURN                                                   1

Class ArrayIterator@anonymous:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YQIVJ
function name:  __construct
number of ops:  8
compiled vars:  !0 = $action, !1 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   17     2        ASSIGN_OBJ                                               'action'
          3        OP_DATA                                                  !0
   19     4        INIT_STATIC_METHOD_CALL                                  
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0          
   20     7      > RETURN                                                   null

End of function __construct

End of class ArrayIterator@anonymous.

Class Action:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YQIVJ
function name:  __construct
number of ops:  17
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
   10     1        DECLARE_ANON_CLASS                               <reference>   'arrayiterator'
          2        NEW                                              $3      $2
          3        FETCH_THIS                                       $4      
          4        SEND_VAR_EX                                              $4
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
          7        ASSIGN_OBJ                                               'generator'
          8        OP_DATA                                                  $3
   23     9        INIT_FCALL                                               'spl_object_id'
         10        FETCH_THIS                                       ~6      
         11        SEND_VAL                                                 ~6
         12        DO_ICALL                                         $7      
         13        CONCAT                                           ~8      '--+c+', $7
         14        CONCAT                                           ~9      ~8, '%0A'
         15        ECHO                                                     ~9
   24    16      > 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/YQIVJ
function name:  __destruct
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   INIT_FCALL                                               'spl_object_id'
          1        FETCH_THIS                                       ~0      
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4        CONCAT                                           ~2      '--+d+', $1
          5        CONCAT                                           ~3      ~2, '%0A'
          6        ECHO                                                     ~3
   29     7      > RETURN                                                   null

End of function __destruct

Function filter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YQIVJ
function name:  filter
number of ops:  16
compiled vars:  !0 = $filterFx
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   DECLARE_LAMBDA_FUNCTION                          ~1      [0]
          1        ASSIGN                                                   !0, ~1
   39     2        NEW                                              $4      'CallbackFilterIterator'
          3        CHECK_FUNC_ARG                                           
          4        FETCH_OBJ_FUNC_ARG                               $5      'generator'
          5        SEND_FUNC_ARG                                            $5
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0          
          8        ASSIGN_OBJ                                               'generator'
          9        OP_DATA                                                  $4
   40    10        FETCH_OBJ_R                                      ~7      'generator'
         11        INIT_METHOD_CALL                                         ~7, 'rewind'
         12        DO_FCALL                                      0          
   42    13        FETCH_THIS                                       ~9      
         14      > RETURN                                                   ~9
   43    15*     > 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/YQIVJ
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
   37     1        FETCH_THIS                                       ~1      
          2        IS_NOT_IDENTICAL                                 ~2      !0, ~1
          3      > RETURN                                                   ~2
   38     4*     > RETURN                                                   null

End of Dynamic Function 0

End of function filter

Function limit:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YQIVJ
function name:  limit
number of ops:  19
compiled vars:  !0 = $limit, !1 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   RECV_INIT                                        !0      null
          1        RECV_INIT                                        !1      0
   50     2        NEW                                              $3      'LimitIterator'
          3        CHECK_FUNC_ARG                                           
          4        FETCH_OBJ_FUNC_ARG                               $4      'generator'
          5        SEND_FUNC_ARG                                            $4
          6        SEND_VAR_EX                                              !1
          7        COALESCE                                         ~5      !0
          8        QM_ASSIGN                                        ~5      -1
          9        SEND_VAL_EX                                              ~5
         10        DO_FCALL                                      0          
         11        ASSIGN_OBJ                                               'generator'
         12        OP_DATA                                                  $3
   51    13        FETCH_OBJ_R                                      ~7      'generator'
         14        INIT_METHOD_CALL                                         ~7, 'rewind'
         15        DO_FCALL                                      0          
   53    16        FETCH_THIS                                       ~9      
         17      > RETURN                                                   ~9
   54    18*     > RETURN                                                   null

End of function limit

End of class Action.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.42 ms | 1021 KiB | 17 Q