3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getusername($user) { return 'genericUser'; } function test ($user) { { // original question $usernameA = $user ?: getusername($user); echo '$usernameA = ', var_export($usernameA, true), PHP_EOL; } { // equivalent if( $user ) { $usernameB = $user; } else { $usernameB = getusername($user); } echo '$usernameB = ', var_export($usernameB, true), PHP_EOL; } } $testCases = array('someUser', true, '', null, false, 0, @$undefined); foreach ( $testCases as $testCase ) { echo 'test with ', var_export($testCase , true) ,' ...', PHP_EOL; test($testCase); echo 'test with ', var_export($testCase , true) ,' DONE.', PHP_EOL; echo PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 34
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 34
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/6XMc4
function name:  (null)
number of ops:  36
compiled vars:  !0 = $testCases, !1 = $testCase
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   INIT_ARRAY                                       ~2      'someUser'
          1        ADD_ARRAY_ELEMENT                                ~2      <true>
          2        ADD_ARRAY_ELEMENT                                ~2      ''
          3        ADD_ARRAY_ELEMENT                                ~2      null
          4        ADD_ARRAY_ELEMENT                                ~2      <false>
          5        ADD_ARRAY_ELEMENT                                ~2      0
          6        BEGIN_SILENCE                                    ~3      
          7        FETCH_R                      local               ~4      'undefined'
          8        END_SILENCE                                              ~3
          9        ADD_ARRAY_ELEMENT                                ~2      ~4
         10        ASSIGN                                                   !0, ~2
   32    11      > FE_RESET_R                                       $6      !0, ->34
         12    > > FE_FETCH_R                                               $6, !1, ->34
   34    13    >   ECHO                                                     'test+with+'
         14        INIT_FCALL                                               'var_export'
         15        SEND_VAR                                                 !1
         16        SEND_VAL                                                 <true>
         17        DO_ICALL                                         $7      
         18        ECHO                                                     $7
         19        ECHO                                                     '+...'
         20        ECHO                                                     '%0A'
   35    21        INIT_FCALL                                               'test'
         22        SEND_VAR                                                 !1
         23        DO_FCALL                                      0          
   36    24        ECHO                                                     'test+with+'
         25        INIT_FCALL                                               'var_export'
         26        SEND_VAR                                                 !1
         27        SEND_VAL                                                 <true>
         28        DO_ICALL                                         $9      
         29        ECHO                                                     $9
         30        ECHO                                                     '+DONE.'
         31        ECHO                                                     '%0A'
   37    32        ECHO                                                     '%0A'
   32    33      > JMP                                                      ->12
         34    >   FE_FREE                                                  $6
   38    35      > RETURN                                                   1

Function getusername:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6XMc4
function name:  getusername
number of ops:  3
compiled vars:  !0 = $user
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1      > RETURN                                                   'genericUser'
    6     2*     > RETURN                                                   null

End of function getusername

Function test:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6XMc4
function name:  test
number of ops:  29
compiled vars:  !0 = $user, !1 = $usernameA, !2 = $usernameB
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
   11     1        JMP_SET                                          ~3      !0, ->6
          2        INIT_FCALL                                               'getusername'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $4      
          5        QM_ASSIGN                                        ~3      $4
          6        ASSIGN                                                   !1, ~3
   13     7        ECHO                                                     '%24usernameA+%3D+'
          8        INIT_FCALL                                               'var_export'
          9        SEND_VAR                                                 !1
         10        SEND_VAL                                                 <true>
         11        DO_ICALL                                         $6      
         12        ECHO                                                     $6
         13        ECHO                                                     '%0A'
   17    14      > JMPZ                                                     !0, ->17
   19    15    >   ASSIGN                                                   !2, !0
   17    16      > JMP                                                      ->21
   23    17    >   INIT_FCALL                                               'getusername'
         18        SEND_VAR                                                 !0
         19        DO_FCALL                                      0  $8      
         20        ASSIGN                                                   !2, $8
   26    21    >   ECHO                                                     '%24usernameB+%3D+'
         22        INIT_FCALL                                               'var_export'
         23        SEND_VAR                                                 !2
         24        SEND_VAL                                                 <true>
         25        DO_ICALL                                         $10     
         26        ECHO                                                     $10
         27        ECHO                                                     '%0A'
   28    28      > RETURN                                                   null

End of function test

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
229.72 ms | 962 KiB | 17 Q