3v4l.org

run code in 300+ PHP versions simultaneously
<?php class lazyNew implements Iterator { private $obj = null; private $func ; public function __construct($func) { $this->func = $func; } public function init() { if ($this->obj === null) { $func = $this->func; $this->obj = $func(); } return $this->obj; } public function current() { return $this->init()->current(); } public function valid() { echo "valid on ".get_class($this)."\n"; //also try var_dump($this) return $this->init()->valid(); } public function next() { return $this->init()->next(); } public function key() { return $this->init()->key(); } public function rewind() { echo "rewind on ".get_class($this)."\n"; return $this->init()->rewind(); } } $P = new lazyNew(function() use (&$P) { return $P = new ArrayIterator(array(1,2,3,4,5)); }); foreach ($P as $val) echo($val); ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/ZcpQZ
function name:  (null)
number of ops:  13
compiled vars:  !0 = $P, !1 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   DECLARE_CLASS                                            'lazynew'
   36     1        NEW                                              $2      'lazyNew'
          2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FZcpQZ%3A36%241'
          3        BIND_LEXICAL                                             ~3, !0
   38     4        SEND_VAL_EX                                              ~3
          5        DO_FCALL                                      0          
   36     6        ASSIGN                                                   !0, $2
   40     7      > FE_RESET_R                                       $6      !0, ->11
          8    > > FE_FETCH_R                                               $6, !1, ->11
          9    >   ECHO                                                     !1
         10      > JMP                                                      ->8
         11    >   FE_FREE                                                  $6
   42    12      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FZcpQZ%3A36%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZcpQZ
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $P
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   BIND_STATIC                                              !0
   37     1        NEW                                              $1      'ArrayIterator'
          2        SEND_VAL_EX                                              <array>
          3        DO_FCALL                                      0          
          4        ASSIGN                                           ~3      !0, $1
          5      > RETURN                                                   ~3
   38     6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FZcpQZ%3A36%241

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

End of function __construct

Function init:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/ZcpQZ
function name:  init
number of ops:  12
compiled vars:  !0 = $func
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   FETCH_OBJ_R                                      ~1      'obj'
          1        TYPE_CHECK                                    2          ~1
          2      > JMPZ                                                     ~2, ->9
   10     3    >   FETCH_OBJ_R                                      ~3      'func'
          4        ASSIGN                                                   !0, ~3
   11     5        INIT_DYNAMIC_CALL                                        !0
          6        DO_FCALL                                      0  $6      
          7        ASSIGN_OBJ                                               'obj'
          8        OP_DATA                                                  $6
   13     9    >   FETCH_OBJ_R                                      ~7      'obj'
         10      > RETURN                                                   ~7
   14    11*     > RETURN                                                   null

End of function init

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

End of function current

Function valid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZcpQZ
function name:  valid
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   FETCH_THIS                                       ~0      
          1        GET_CLASS                                        ~1      ~0
          2        CONCAT                                           ~2      'valid+on+', ~1
          3        CONCAT                                           ~3      ~2, '%0A'
          4        ECHO                                                     ~3
   21     5        INIT_METHOD_CALL                                         'init'
          6        DO_FCALL                                      0  $4      
          7        INIT_METHOD_CALL                                         $4, 'valid'
          8        DO_FCALL                                      0  $5      
          9      > RETURN                                                   $5
   22    10*     > RETURN                                                   null

End of function valid

Function next:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZcpQZ
function name:  next
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   INIT_METHOD_CALL                                         'init'
          1        DO_FCALL                                      0  $0      
          2        INIT_METHOD_CALL                                         $0, 'next'
          3        DO_FCALL                                      0  $1      
          4      > RETURN                                                   $1
   25     5*     > 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/ZcpQZ
function name:  key
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   INIT_METHOD_CALL                                         'init'
          1        DO_FCALL                                      0  $0      
          2        INIT_METHOD_CALL                                         $0, 'key'
          3        DO_FCALL                                      0  $1      
          4      > RETURN                                                   $1
   28     5*     > RETURN                                                   null

End of function key

Function rewind:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZcpQZ
function name:  rewind
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   FETCH_THIS                                       ~0      
          1        GET_CLASS                                        ~1      ~0
          2        CONCAT                                           ~2      'rewind+on+', ~1
          3        CONCAT                                           ~3      ~2, '%0A'
          4        ECHO                                                     ~3
   31     5        INIT_METHOD_CALL                                         'init'
          6        DO_FCALL                                      0  $4      
          7        INIT_METHOD_CALL                                         $4, 'rewind'
          8        DO_FCALL                                      0  $5      
          9      > RETURN                                                   $5
   32    10*     > RETURN                                                   null

End of function rewind

End of class lazyNew.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.07 ms | 1407 KiB | 13 Q