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; } //@Big-Shark function v2($first, $last) { return trim(implode(" ", [$first, $last])); } //@Hunternnm function v3($first, $last) { if(strlen(trim($first)) > 0 && strlen(trim($last)) > 0) { return $first." ".$last; } if(strlen(trim($first)) > 0) { return trim($first); } else { return trim($last); } } //@NelinD function v4($first, $last) { return implode(' ', array_filter([$first, $last], function ($string) { return trim($string); })); } //@NelinD function v5($first, $last) { return trim(trim($first).' '.trim($last)); } //@Big-Shark function v6($first, $last) { return trim($first.' '.$last); } function v($first, $last) { var_dump( v1($first, $last) ); var_dump( v2($first, $last) ); var_dump( v3($first, $last) ); var_dump( v4($first, $last) ); var_dump( v5($first, $last) ); var_dump( v6($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/np1p0
function name:  (null)
number of ops:  25
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   INIT_FCALL                                               'v'
          1        SEND_VAL                                                 'first'
          2        SEND_VAL                                                 'last'
          3        DO_FCALL                                      0          
   70     4        INIT_FCALL                                               'v'
          5        SEND_VAL                                                 'first'
          6        SEND_VAL                                                 ''
          7        DO_FCALL                                      0          
   71     8        INIT_FCALL                                               'v'
          9        SEND_VAL                                                 'first'
         10        SEND_VAL                                                 '+'
         11        DO_FCALL                                      0          
   72    12        INIT_FCALL                                               'v'
         13        SEND_VAL                                                 ''
         14        SEND_VAL                                                 '+%D0%B2+last'
         15        DO_FCALL                                      0          
   73    16        INIT_FCALL                                               'v'
         17        SEND_VAL                                                 '+'
         18        SEND_VAL                                                 '+%D0%B2+last'
         19        DO_FCALL                                      0          
   74    20        INIT_FCALL                                               'v'
         21        SEND_VAL                                                 '+'
         22        SEND_VAL                                                 '+%D0%B2+last'
         23        DO_FCALL                                      0          
         24      > 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/np1p0
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, '+'
   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/np1p0
function name:  v2
number of ops:  13
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                                               'trim'
          3        INIT_FCALL                                               'implode'
          4        SEND_VAL                                                 '+'
          5        INIT_ARRAY                                       ~2      !0
          6        ADD_ARRAY_ELEMENT                                ~2      !1
          7        SEND_VAL                                                 ~2
          8        DO_ICALL                                         $3      
          9        SEND_VAR                                                 $3
         10        DO_ICALL                                         $4      
         11      > RETURN                                                   $4
   21    12*     > RETURN                                                   null

End of function v2

Function v3:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 18
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 29
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/np1p0
function name:  v3
number of ops:  34
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        INIT_FCALL                                               'trim'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        STRLEN                                           ~3      $2
          6        IS_SMALLER                                       ~4      0, ~3
          7      > JMPZ_EX                                          ~4      ~4, ->14
          8    >   INIT_FCALL                                               'trim'
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $5      
         11        STRLEN                                           ~6      $5
         12        IS_SMALLER                                       ~7      0, ~6
         13        BOOL                                             ~4      ~7
         14    > > JMPZ                                                     ~4, ->18
   27    15    >   CONCAT                                           ~8      !0, '+'
         16        CONCAT                                           ~9      ~8, !1
         17      > RETURN                                                   ~9
   30    18    >   INIT_FCALL                                               'trim'
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                         $10     
         21        STRLEN                                           ~11     $10
         22        IS_SMALLER                                               0, ~11
         23      > JMPZ                                                     ~12, ->29
   31    24    >   INIT_FCALL                                               'trim'
         25        SEND_VAR                                                 !0
         26        DO_ICALL                                         $13     
         27      > RETURN                                                   $13
         28*       JMP                                                      ->33
   33    29    >   INIT_FCALL                                               'trim'
         30        SEND_VAR                                                 !1
         31        DO_ICALL                                         $14     
         32      > RETURN                                                   $14
   35    33*     > 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/np1p0
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                                                 '+'
          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%2Fnp1p0%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%2Fnp1p0%3A40%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/np1p0
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%2Fnp1p0%3A40%240

Function v5:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/np1p0
function name:  v5
number of ops:  15
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                                               'trim'
          3        INIT_FCALL                                               'trim'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6        CONCAT                                           ~3      $2, '+'
          7        INIT_FCALL                                               'trim'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $4      
         10        CONCAT                                           ~5      ~3, $4
         11        SEND_VAL                                                 ~5
         12        DO_ICALL                                         $6      
         13      > RETURN                                                   $6
   49    14*     > RETURN                                                   null

End of function v5

Function v6:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/np1p0
function name:  v6
number of ops:  9
compiled vars:  !0 = $first, !1 = $last
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   54     2        INIT_FCALL                                               'trim'
          3        CONCAT                                           ~2      !0, '+'
          4        CONCAT                                           ~3      ~2, !1
          5        SEND_VAL                                                 ~3
          6        DO_ICALL                                         $4      
          7      > RETURN                                                   $4
   55     8*     > RETURN                                                   null

End of function v6

Function v:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/np1p0
function name:  v
number of ops:  47
compiled vars:  !0 = $first, !1 = $last
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   59     2        INIT_FCALL                                               'var_dump'
          3        INIT_FCALL                                               'v1'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $2      
          7        SEND_VAR                                                 $2
          8        DO_ICALL                                                 
   60     9        INIT_FCALL                                               'var_dump'
         10        INIT_FCALL                                               'v2'
         11        SEND_VAR                                                 !0
         12        SEND_VAR                                                 !1
         13        DO_FCALL                                      0  $4      
         14        SEND_VAR                                                 $4
         15        DO_ICALL                                                 
   61    16        INIT_FCALL                                               'var_dump'
         17        INIT_FCALL                                               'v3'
         18        SEND_VAR                                                 !0
         19        SEND_VAR                                                 !1
         20        DO_FCALL                                      0  $6      
         21        SEND_VAR                                                 $6
         22        DO_ICALL                                                 
   62    23        INIT_FCALL                                               'var_dump'
         24        INIT_FCALL                                               'v4'
         25        SEND_VAR                                                 !0
         26        SEND_VAR                                                 !1
         27        DO_FCALL                                      0  $8      
         28        SEND_VAR                                                 $8
         29        DO_ICALL                                                 
   63    30        INIT_FCALL                                               'var_dump'
         31        INIT_FCALL                                               'v5'
         32        SEND_VAR                                                 !0
         33        SEND_VAR                                                 !1
         34        DO_FCALL                                      0  $10     
         35        SEND_VAR                                                 $10
         36        DO_ICALL                                                 
   64    37        INIT_FCALL                                               'var_dump'
         38        INIT_FCALL                                               'v6'
         39        SEND_VAR                                                 !0
         40        SEND_VAR                                                 !1
         41        DO_FCALL                                      0  $12     
         42        SEND_VAR                                                 $12
         43        DO_ICALL                                                 
   65    44        ECHO                                                     '%0A'
   66    45        ECHO                                                     '%0A'
   67    46      > RETURN                                                   null

End of function v

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.53 ms | 1415 KiB | 33 Q