3v4l.org

run code in 500+ PHP versions simultaneously
<?php // Weakmaps accepts objects and arrays as keys $source = new Weakmap(); $key = (object) ['a' => 2]; $source[$key] = 1; // Yield may emit objects and arrays as keys $source = function () { yield (object) ['a' => 3] => 1; }; // This is just for illustration $source = $source(); // An iterator may return objects and arrays as keys(mixed, in fact) class myIterator implements Iterator { private int $position = 0; public function rewind(): void { $this->position = 0; } public function current(): mixed { return 1; } public function key(): mixed { return (object) ['a' => 4]; } public function next(): void { ++$this->position; } public function valid(): bool { return $this->position == 0; } } $source = new myIterator(); foreach($source as $key => $value) { print get_class($key); // Stdclass print $value; // 1 }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 23
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 23
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/OVvKR
function name:  (null)
number of ops:  25
compiled vars:  !0 = $source, !1 = $key, !2 = $value
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   NEW                                                  $3      'Weakmap'
          1        DO_FCALL                                          0          
          2        ASSIGN                                                       !0, $3
    5     3        CAST                                              8  ~6      <array>
          4        ASSIGN                                                       !1, ~6
    6     5        ASSIGN_DIM                                                   !0, !1
          6        OP_DATA                                                      1
    9     7        DECLARE_LAMBDA_FUNCTION                              ~9      [0]
          8        ASSIGN                                                       !0, ~9
   13     9        INIT_DYNAMIC_CALL                                            !0
         10        DO_FCALL                                          0  $11     
         11        ASSIGN                                                       !0, $11
   16    12        DECLARE_CLASS                                                'myiterator'
   27    13        NEW                                                  $13     'myIterator'
         14        DO_FCALL                                          0          
         15        ASSIGN                                                       !0, $13
   29    16      > FE_RESET_R                                           $16     !0, ->23
         17    > > FE_FETCH_R                                           ~17     $16, !2, ->23
         18    >   ASSIGN                                                       !1, ~17
   30    19        GET_CLASS                                            ~19     !1
         20        ECHO                                                         ~19
   31    21        ECHO                                                         !2
   29    22      > JMP                                                          ->17
         23    >   FE_FREE                                                      $16
   32    24      > 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/OVvKR
function name:  {closure:/in/OVvKR:9}
number of ops:  4
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    9     0  E >   GENERATOR_CREATE                                             
   10     1        CAST                                              8  ~0      <array>
          2        YIELD                                                        1, ~0
   11     3      > GENERATOR_RETURN                                             

End of Dynamic Function 0

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

End of function rewind

Function current:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OVvKR
function name:  current
number of ops:  3
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   20     0  E > > RETURN                                                       1
          1*       VERIFY_RETURN_TYPE                                           
          2*     > RETURN                                                       null

End of function current

Function key:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OVvKR
function name:  key
number of ops:  4
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   22     0  E >   CAST                                              8  ~0      <array>
          1      > RETURN                                                       ~0
   23     2*       VERIFY_RETURN_TYPE                                           
          3*     > RETURN                                                       null

End of function key

Function next:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OVvKR
function name:  next
number of ops:  2
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   24     0  E >   PRE_INC_OBJ                                                  'position'
          1      > RETURN                                                       null

End of function next

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

End of function valid

End of class myIterator.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
156.82 ms | 1406 KiB | 13 Q