3v4l.org

run code in 300+ PHP versions simultaneously
<?php //old code function v1($first, $last) { $result = trim($first); $lastName = trim($last); if ($lastName) { if (!empty($result)) { $result .= ','; } $result .= $lastName; } return $result; } //my function v2($first, $last) { return implode(",", [trim($first), trim($last)]); } //@Hunternnm function v3($first, $last) { if(strlen($first) > 0 && strlen($last) > 0) { return $first.",".$last; } if(strlen($first) > 0) { return $first; } else { return $last; } } //@NelinD function v4($first, $last) { return implode(',', array_filter([$first, $last], function ($string) { return trim($string); })); } function v($first, $last) { echo v1($first, $last); echo PHP_EOL; echo v2($first, $last); echo PHP_EOL; echo v3($first, $last); echo PHP_EOL; echo v4($first, $last); echo PHP_EOL; echo PHP_EOL; } v('first', 'last'); v('first', ''); v('first', ' '); v('', last); v(' ', last); v(' ', last);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IXKBB
function name:  (null)
number of ops:  28
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   INIT_FCALL                                               'v'
          1        SEND_VAL                                                 'first'
          2        SEND_VAL                                                 'last'
          3        DO_FCALL                                      0          
   60     4        INIT_FCALL                                               'v'
          5        SEND_VAL                                                 'first'
          6        SEND_VAL                                                 ''
          7        DO_FCALL                                      0          
   61     8        INIT_FCALL                                               'v'
          9        SEND_VAL                                                 'first'
         10        SEND_VAL                                                 '+'
         11        DO_FCALL                                      0          
   62    12        INIT_FCALL                                               'v'
         13        SEND_VAL                                                 ''
         14        FETCH_CONSTANT                                   ~3      'last'
         15        SEND_VAL                                                 ~3
         16        DO_FCALL                                      0          
   63    17        INIT_FCALL                                               'v'
         18        SEND_VAL                                                 '+'
         19        FETCH_CONSTANT                                   ~5      'last'
         20        SEND_VAL                                                 ~5
         21        DO_FCALL                                      0          
   64    22        INIT_FCALL                                               'v'
         23        SEND_VAL                                                 '+'
         24        FETCH_CONSTANT                                   ~7      'last'
         25        SEND_VAL                                                 ~7
         26        DO_FCALL                                      0          
         27      > RETURN                                                   1

Function v1:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 16
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 15
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
Branch analysis from position: 16
filename:       /in/IXKBB
function name:  v1
number of ops:  18
compiled vars:  !0 = $first, !1 = $last, !2 = $result, !3 = $lastName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        INIT_FCALL                                               'trim'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $4      
          5        ASSIGN                                                   !2, $4
    6     6        INIT_FCALL                                               'trim'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $6      
          9        ASSIGN                                                   !3, $6
    7    10      > JMPZ                                                     !3, ->16
    8    11    >   ISSET_ISEMPTY_CV                                 ~8      !2
         12        BOOL_NOT                                         ~9      ~8
         13      > JMPZ                                                     ~9, ->15
    9    14    >   ASSIGN_OP                                     8          !2, '%2C'
   11    15    >   ASSIGN_OP                                     8          !2, !3
   14    16    > > RETURN                                                   !2
   15    17*     > RETURN                                                   null

End of function v1

Function v2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IXKBB
function name:  v2
number of ops:  16
compiled vars:  !0 = $first, !1 = $last
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   20     2        INIT_FCALL                                               'implode'
          3        SEND_VAL                                                 '%2C'
          4        INIT_FCALL                                               'trim'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $2      
          7        INIT_ARRAY                                       ~3      $2
          8        INIT_FCALL                                               'trim'
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $4      
         11        ADD_ARRAY_ELEMENT                                ~3      $4
         12        SEND_VAL                                                 ~3
         13        DO_ICALL                                         $5      
         14      > RETURN                                                   $5
   21    15*     > RETURN                                                   null

End of function v2

Function v3:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 12
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/IXKBB
function name:  v3
number of ops:  19
compiled vars:  !0 = $first, !1 = $last
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   26     2        STRLEN                                           ~2      !0
          3        IS_SMALLER                                       ~3      0, ~2
          4      > JMPZ_EX                                          ~3      ~3, ->8
          5    >   STRLEN                                           ~4      !1
          6        IS_SMALLER                                       ~5      0, ~4
          7        BOOL                                             ~3      ~5
          8    > > JMPZ                                                     ~3, ->12
   27     9    >   CONCAT                                           ~6      !0, '%2C'
         10        CONCAT                                           ~7      ~6, !1
         11      > RETURN                                                   ~7
   30    12    >   STRLEN                                           ~8      !0
         13        IS_SMALLER                                               0, ~8
         14      > JMPZ                                                     ~9, ->17
   31    15    > > RETURN                                                   !0
         16*       JMP                                                      ->18
   33    17    > > RETURN                                                   !1
   35    18*     > RETURN                                                   null

End of function v3

Function v4:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IXKBB
function name:  v4
number of ops:  15
compiled vars:  !0 = $first, !1 = $last
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   40     2        INIT_FCALL                                               'implode'
          3        SEND_VAL                                                 '%2C'
          4        INIT_FCALL                                               'array_filter'
          5        INIT_ARRAY                                       ~2      !0
          6        ADD_ARRAY_ELEMENT                                ~2      !1
          7        SEND_VAL                                                 ~2
          8        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FIXKBB%3A40%240'
   42     9        SEND_VAL                                                 ~3
         10        DO_ICALL                                         $4      
         11        SEND_VAR                                                 $4
         12        DO_ICALL                                         $5      
         13      > RETURN                                                   $5
   43    14*     > RETURN                                                   null

End of function v4

Function %00%7Bclosure%7D%2Fin%2FIXKBB%3A40%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IXKBB
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
   41     1        INIT_FCALL                                               'trim'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
   42     5*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FIXKBB%3A40%240

Function v:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IXKBB
function name:  v
number of ops:  28
compiled vars:  !0 = $first, !1 = $last
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   48     2        INIT_FCALL                                               'v1'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $2      
          6        ECHO                                                     $2
   49     7        ECHO                                                     '%0A'
   50     8        INIT_FCALL                                               'v2'
          9        SEND_VAR                                                 !0
         10        SEND_VAR                                                 !1
         11        DO_FCALL                                      0  $3      
         12        ECHO                                                     $3
   51    13        ECHO                                                     '%0A'
   52    14        INIT_FCALL                                               'v3'
         15        SEND_VAR                                                 !0
         16        SEND_VAR                                                 !1
         17        DO_FCALL                                      0  $4      
         18        ECHO                                                     $4
   53    19        ECHO                                                     '%0A'
   54    20        INIT_FCALL                                               'v4'
         21        SEND_VAR                                                 !0
         22        SEND_VAR                                                 !1
         23        DO_FCALL                                      0  $5      
         24        ECHO                                                     $5
   55    25        ECHO                                                     '%0A'
   56    26        ECHO                                                     '%0A'
   57    27      > RETURN                                                   null

End of function v

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.1 ms | 1411 KiB | 29 Q