3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Bar{} $bars = [new Bar, new Bar, new Bar]; $ints = [1, 2, 3]; // php 5.6 style function foo(Bar ...$bars) { echo "Got " . count($bars) . " bars.\n"; } foo(...$bars); // fatal error //foo(...$ints); // without variadics function oldFoo($bars) { foreach ($bars as $bar) { if (!$bar instanceof Bar) { throw new InvalidArgumentException("Must be a Bar."); } } echo "Got " . count($bars) . " bars.\n"; } oldFoo($bars); // InvalidArgumentException oldFoo($ints);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/H79mA
function name:  (null)
number of ops:  22
compiled vars:  !0 = $bars, !1 = $ints
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   NEW                                              $2      'Bar'
          1        DO_FCALL                                      0          
          2        INIT_ARRAY                                       ~4      $2
          3        NEW                                              $5      'Bar'
          4        DO_FCALL                                      0          
          5        ADD_ARRAY_ELEMENT                                ~4      $5
          6        NEW                                              $7      'Bar'
          7        DO_FCALL                                      0          
          8        ADD_ARRAY_ELEMENT                                ~4      $7
          9        ASSIGN                                                   !0, ~4
    5    10        ASSIGN                                                   !1, <array>
   13    11        INIT_FCALL                                               'foo'
         12        SEND_UNPACK                                              !0
         13        CHECK_UNDEF_ARGS                                         
         14        DO_FCALL                                      1          
   30    15        INIT_FCALL                                               'oldfoo'
         16        SEND_VAR                                                 !0
         17        DO_FCALL                                      0          
   33    18        INIT_FCALL                                               'oldfoo'
         19        SEND_VAR                                                 !1
         20        DO_FCALL                                      0          
         21      > RETURN                                                   1

Function foo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/H79mA
function name:  foo
number of ops:  6
compiled vars:  !0 = $bars
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV_VARIADIC                                    !0      
   10     1        COUNT                                            ~1      !0
          2        CONCAT                                           ~2      'Got+', ~1
          3        CONCAT                                           ~3      ~2, '+bars.%0A'
          4        ECHO                                                     ~3
   11     5      > RETURN                                                   null

End of function foo

Function oldfoo:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 11
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 11
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/H79mA
function name:  oldFoo
number of ops:  17
compiled vars:  !0 = $bars, !1 = $bar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   22     1      > FE_RESET_R                                       $2      !0, ->11
          2    > > FE_FETCH_R                                               $2, !1, ->11
   23     3    >   INSTANCEOF                                       ~3      !1, 'Bar'
          4        BOOL_NOT                                         ~4      ~3
          5      > JMPZ                                                     ~4, ->10
   24     6    >   NEW                                              $5      'InvalidArgumentException'
          7        SEND_VAL_EX                                              'Must+be+a+Bar.'
          8        DO_FCALL                                      0          
          9      > THROW                                         0          $5
   22    10    > > JMP                                                      ->2
         11    >   FE_FREE                                                  $2
   27    12        COUNT                                            ~7      !0
         13        CONCAT                                           ~8      'Got+', ~7
         14        CONCAT                                           ~9      ~8, '+bars.%0A'
         15        ECHO                                                     ~9
   28    16      > RETURN                                                   null

End of function oldfoo

Class Bar: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.96 ms | 1403 KiB | 16 Q