3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * PHP 5.6 Variadics allow us to pack arguments into arrays from the function prototype! * Typically you would use a combination of func_get_args and array_slice to grab these * function arguments from the stack frame, but Variadics make the syntax much nicer. */ // Pre PHP 5.6 you would do the following ... function bond($agent) { $bondingAgents = array_slice(func_get_args(), 1); $bonding = ""; foreach ($bondingAgents as $bond) { $bonding .= "$agent-$bond\n"; } return $bonding; } // With PHp 5.6 you cna do this instead ... function newBond($agent, ...$bondingAgents) { $bonding = ""; foreach($bondingAgents as $bond) { $bonding .= "$agent-$bond\n"; } return $bonding; } header('Content-type: text/plain'); echo "Pre-5.6 Result...\n\n"; echo bond("Hydrogen", "Oxide", "Peroxide", "Dioxide"); echo "5.6 Result...\n\n"; echo newBond("Hydrogen", "Oxide", "Peroxide", "Dioxide");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FR8n0
function name:  (null)
number of ops:  20
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   INIT_FCALL                                               'header'
          1        SEND_VAL                                                 'Content-type%3A+text%2Fplain'
          2        DO_ICALL                                                 
   29     3        ECHO                                                     'Pre-5.6+Result...%0A%0A'
   30     4        INIT_FCALL                                               'bond'
          5        SEND_VAL                                                 'Hydrogen'
          6        SEND_VAL                                                 'Oxide'
          7        SEND_VAL                                                 'Peroxide'
          8        SEND_VAL                                                 'Dioxide'
          9        DO_FCALL                                      0  $1      
         10        ECHO                                                     $1
   32    11        ECHO                                                     '5.6+Result...%0A%0A'
   33    12        INIT_FCALL                                               'newbond'
         13        SEND_VAL                                                 'Hydrogen'
         14        SEND_VAL                                                 'Oxide'
         15        SEND_VAL                                                 'Peroxide'
         16        SEND_VAL                                                 'Dioxide'
         17        DO_FCALL                                      0  $2      
         18        ECHO                                                     $2
         19      > RETURN                                                   1

Function bond:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/FR8n0
function name:  bond
number of ops:  15
compiled vars:  !0 = $agent, !1 = $bondingAgents, !2 = $bonding, !3 = $bond
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        FUNC_GET_ARGS                                    ~4      1
          2        ASSIGN                                                   !1, ~4
   11     3        ASSIGN                                                   !2, ''
   12     4      > FE_RESET_R                                       $7      !1, ->12
          5    > > FE_FETCH_R                                               $7, !3, ->12
   13     6    >   ROPE_INIT                                     4  ~9      !0
          7        ROPE_ADD                                      1  ~9      ~9, '-'
          8        ROPE_ADD                                      2  ~9      ~9, !3
          9        ROPE_END                                      3  ~8      ~9, '%0A'
         10        ASSIGN_OP                                     8          !2, ~8
   12    11      > JMP                                                      ->5
         12    >   FE_FREE                                                  $7
   15    13      > RETURN                                                   !2
   16    14*     > RETURN                                                   null

End of function bond

Function newbond:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/FR8n0
function name:  newBond
number of ops:  14
compiled vars:  !0 = $agent, !1 = $bondingAgents, !2 = $bonding, !3 = $bond
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        RECV_VARIADIC                                    !1      
   20     2        ASSIGN                                                   !2, ''
   21     3      > FE_RESET_R                                       $5      !1, ->11
          4    > > FE_FETCH_R                                               $5, !3, ->11
   22     5    >   ROPE_INIT                                     4  ~7      !0
          6        ROPE_ADD                                      1  ~7      ~7, '-'
          7        ROPE_ADD                                      2  ~7      ~7, !3
          8        ROPE_END                                      3  ~6      ~7, '%0A'
          9        ASSIGN_OP                                     8          !2, ~6
   21    10      > JMP                                                      ->4
         11    >   FE_FREE                                                  $5
   24    12      > RETURN                                                   !2
   25    13*     > RETURN                                                   null

End of function newbond

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.86 ms | 1403 KiB | 17 Q