3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Collection { public $fixedArray; public function __construct(SplFixedArray $splFixedArray) { $this->fixedArray = $splFixedArray; } public function getSum() { $sum = 0; $arr = $this->fixedArray; foreach ($arr as $item) { $sum += $item; } return $sum; } } $spl = SplFixedArray::fromArray([0, 1, 2]); $collection = new Collection($spl); $collArr = $collection->fixedArray; $i = 0; foreach ($collArr as $item) { echo '-- iteration: ' . $i . ', sum: ' . $collection->getSum() . PHP_EOL; $i++; } echo 'Expected 3 iterations, executed ' . $i . PHP_EOL;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 22
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 22
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/FdN4i
function name:  (null)
number of ops:  27
compiled vars:  !0 = $spl, !1 = $collection, !2 = $collArr, !3 = $i, !4 = $item
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   25     0  E >   INIT_STATIC_METHOD_CALL                                      'SplFixedArray', 'fromArray'
          1        SEND_VAL                                                     <array>
          2        DO_FCALL                                          0  $5      
          3        ASSIGN                                                       !0, $5
   27     4        NEW                                                  $7      'Collection'
          5        SEND_VAR_EX                                                  !0
          6        DO_FCALL                                          0          
          7        ASSIGN                                                       !1, $7
   28     8        FETCH_OBJ_R                                          ~10     !1, 'fixedArray'
          9        ASSIGN                                                       !2, ~10
   30    10        ASSIGN                                                       !3, 0
   32    11      > FE_RESET_R                                           $13     !2, ->22
         12    > > FE_FETCH_R                                                   $13, !4, ->22
   33    13    >   CONCAT                                               ~14     '--+iteration%3A+', !3
         14        CONCAT                                               ~15     ~14, '%2C+sum%3A+'
         15        INIT_METHOD_CALL                                             !1, 'getSum'
         16        DO_FCALL                                          0  $16     
         17        CONCAT                                               ~17     ~15, $16
         18        CONCAT                                               ~18     ~17, '%0A'
         19        ECHO                                                         ~18
   34    20        PRE_INC                                                      !3
   32    21      > JMP                                                          ->12
         22    >   FE_FREE                                                      $13
   37    23        CONCAT                                               ~20     'Expected+3+iterations%2C+executed+', !3
         24        CONCAT                                               ~21     ~20, '%0A'
         25        ECHO                                                         ~21
   38    26      > RETURN                                                       1

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

End of function __construct

Function getsum:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/FdN4i
function name:  getSum
number of ops:  10
compiled vars:  !0 = $sum, !1 = $arr, !2 = $item
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   ASSIGN                                                       !0, 0
   15     1        FETCH_OBJ_R                                          ~4      'fixedArray'
          2        ASSIGN                                                       !1, ~4
   16     3      > FE_RESET_R                                           $6      !1, ->7
          4    > > FE_FETCH_R                                                   $6, !2, ->7
   17     5    >   ASSIGN_OP                                         1          !0, !2
   16     6      > JMP                                                          ->4
          7    >   FE_FREE                                                      $6
   20     8      > RETURN                                                       !0
   21     9*     > RETURN                                                       null

End of function getsum

End of class Collection.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
171.93 ms | 3339 KiB | 13 Q