3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (PHP_VERSION !== '7.1.6') die('Meh'); function kv(& $a) { $b = $a; end($b); $kv = [$k = key($b), current($b)]; // unset($b); // TRICKY: We must unset $b before modifying $a to avoid copy-on-write for $a. unset($a[$k]); return $kv; } $a = range(1, 2000000); next($a); next($a); echo current($a) . PHP_EOL; var_dump($a); var_dump(kv($a)); echo current($a) . PHP_EOL; var_dump($a);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 1, Position 2 = 2
Branch analysis from position: 1
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 2
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Nhfaf
function name:  (null)
number of ops:  36
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E > > JMPZ                                                     <true>, ->2
          1    > > EXIT                                                     'Meh'
   13     2    >   INIT_FCALL                                               'range'
          3        SEND_VAL                                                 1
          4        SEND_VAL                                                 2000000
          5        DO_ICALL                                         $1      
          6        ASSIGN                                                   !0, $1
   14     7        INIT_FCALL                                               'next'
          8        SEND_REF                                                 !0
          9        DO_ICALL                                                 
         10        INIT_FCALL                                               'next'
         11        SEND_REF                                                 !0
         12        DO_ICALL                                                 
   16    13        INIT_FCALL                                               'current'
         14        SEND_VAR                                                 !0
         15        DO_ICALL                                         $5      
         16        CONCAT                                           ~6      $5, '%0A'
         17        ECHO                                                     ~6
   17    18        INIT_FCALL                                               'var_dump'
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                                 
   18    21        INIT_FCALL                                               'var_dump'
         22        INIT_FCALL                                               'kv'
         23        SEND_REF                                                 !0
         24        DO_FCALL                                      0  $8      
         25        SEND_VAR                                                 $8
         26        DO_ICALL                                                 
   19    27        INIT_FCALL                                               'current'
         28        SEND_VAR                                                 !0
         29        DO_ICALL                                         $10     
         30        CONCAT                                           ~11     $10, '%0A'
         31        ECHO                                                     ~11
   20    32        INIT_FCALL                                               'var_dump'
         33        SEND_VAR                                                 !0
         34        DO_ICALL                                                 
         35      > RETURN                                                   1

Function kv:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Nhfaf
function name:  kv
number of ops:  18
compiled vars:  !0 = $a, !1 = $b, !2 = $kv, !3 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, !0
    6     2        INIT_FCALL                                               'end'
          3        SEND_REF                                                 !1
          4        DO_ICALL                                                 
    7     5        INIT_FCALL                                               'key'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $6      
          8        ASSIGN                                           ~7      !3, $6
          9        INIT_ARRAY                                       ~8      ~7
         10        INIT_FCALL                                               'current'
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                         $9      
         13        ADD_ARRAY_ELEMENT                                ~8      $9
         14        ASSIGN                                                   !2, ~8
    9    15        UNSET_DIM                                                !0, !3
   10    16      > RETURN                                                   !2
   11    17*     > RETURN                                                   null

End of function kv

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.44 ms | 1394 KiB | 26 Q