3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); namespace App; use Generator; use CachingIterator; class Foo { static $i = 0; public function __toString() { echo "Foo::_toString called " . (self::$i + 1) . " times\n"; return "foo " . ((string) ++self::$i); } } $generator = /** * @return Generator<bool, bool> */ static function () { yield true => true; yield false => false; yield "foo" => new Foo(); yield "bar" => new Foo(); yield "baz" => new Foo(); }; $iterator = new CachingIterator($generator(), CachingIterator::FULL_CACHE | CachingIterator::CALL_TOSTRING); foreach ($iterator as $k => $v) { var_dump($k, $v); } foreach ($iterator->getCache() as $k => $v) { var_dump($k, $v); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 18
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 18
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 18
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 29
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 29
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
Branch analysis from position: 18
filename:       /in/Uiv7q
function name:  (null)
number of ops:  31
compiled vars:  !0 = $generator, !1 = $iterator, !2 = $v, !3 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   DECLARE_CLASS                                            'app%5Cfoo'
   25     1        DECLARE_LAMBDA_FUNCTION                          ~4      [0]
   21     2        ASSIGN                                                   !0, ~4
   33     3        NEW                                              $6      'CachingIterator'
          4        INIT_DYNAMIC_CALL                                        !0
          5        DO_FCALL                                      0  $7      
          6        SEND_VAR_NO_REF_EX                                       $7
          7        SEND_VAL_EX                                              257
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !1, $6
   35    10      > FE_RESET_R                                       $10     !1, ->18
         11    > > FE_FETCH_R                                       ~11     $10, !2, ->18
         12    >   ASSIGN                                                   !3, ~11
   36    13        INIT_NS_FCALL_BY_NAME                                    'App%5Cvar_dump'
         14        SEND_VAR_EX                                              !3
         15        SEND_VAR_EX                                              !2
         16        DO_FCALL                                      0          
   35    17      > JMP                                                      ->11
         18    >   FE_FREE                                                  $10
   39    19        INIT_METHOD_CALL                                         !1, 'getCache'
         20        DO_FCALL                                      0  $14     
         21      > FE_RESET_R                                       $15     $14, ->29
         22    > > FE_FETCH_R                                       ~16     $15, !2, ->29
         23    >   ASSIGN                                                   !3, ~16
   40    24        INIT_NS_FCALL_BY_NAME                                    'App%5Cvar_dump'
         25        SEND_VAR_EX                                              !3
         26        SEND_VAR_EX                                              !2
         27        DO_FCALL                                      0          
   39    28      > JMP                                                      ->22
         29    >   FE_FREE                                                  $15
   41    30      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/Uiv7q
function name:  App\{closure}
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   GENERATOR_CREATE                                         
   26     1        YIELD                                                    <true>, <true>
   27     2        YIELD                                                    <false>, <false>
   28     3        NEW                                              $2      'App%5CFoo'
          4        DO_FCALL                                      0          
          5        YIELD                                                    $2, 'foo'
   29     6        NEW                                              $5      'App%5CFoo'
          7        DO_FCALL                                      0          
          8        YIELD                                                    $5, 'bar'
   30     9        NEW                                              $8      'App%5CFoo'
         10        DO_FCALL                                      0          
         11        YIELD                                                    $8, 'baz'
   31    12      > GENERATOR_RETURN                                         

End of Dynamic Function 0

Class App\Foo:
Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Uiv7q
function name:  __toString
number of ops:  12
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   FETCH_STATIC_PROP_R          unknown             ~0      'i'
          1        ADD                                              ~1      ~0, 1
          2        CONCAT                                           ~2      'Foo%3A%3A_toString+called+', ~1
          3        CONCAT                                           ~3      ~2, '+times%0A'
          4        ECHO                                                     ~3
   17     5        PRE_INC_STATIC_PROP                              ~4      'i'
          6        CAST                                          6  ~5      ~4
          7        CONCAT                                           ~6      'foo+', ~5
          8        VERIFY_RETURN_TYPE                                       ~6
          9      > RETURN                                                   ~6
   18    10*       VERIFY_RETURN_TYPE                                       
         11*     > RETURN                                                   null

End of function __tostring

End of class App\Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161 ms | 1015 KiB | 14 Q