3v4l.org

run code in 300+ PHP versions simultaneously
<?php function test_position($input) { $_POST['position'] = $input; // Original code $original = ( isset( $_POST['position'] ) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1'; // Alternative 1: !empty() $empty_check = ! empty( $_POST['position'] ) ? (int) $_POST['position'] : -1; // Alternative 3: null coalescing operator $null_coalesce = (int) ($_POST['position'] ?? '-1'); echo "Input: $input\n"; echo "Original: $original\n"; echo "!empty() check: $empty_check\n"; echo "Null coalescing: $null_coalesce\n"; echo "-------------------------\n"; } // Test cases $test_inputs = ['5', '0', 'xyz', '', null]; foreach ($test_inputs as $input) { test_position($input); } ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 7
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/r5JlV
function name:  (null)
number of ops:  9
compiled vars:  !0 = $test_inputs, !1 = $input
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   ASSIGN                                                   !0, <array>
   24     1      > FE_RESET_R                                       $3      !0, ->7
          2    > > FE_FETCH_R                                               $3, !1, ->7
   25     3    >   INIT_FCALL                                               'test_position'
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0          
   24     6      > JMP                                                      ->2
          7    >   FE_FREE                                                  $3
   27     8      > RETURN                                                   1

Function test_position:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 17
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 28
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 28
Branch analysis from position: 23
Branch analysis from position: 28
Branch analysis from position: 11
filename:       /in/r5JlV
function name:  test_position
number of ops:  54
compiled vars:  !0 = $input, !1 = $original, !2 = $empty_check, !3 = $null_coalesce
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        FETCH_W                      global              $4      '_POST'
          2        ASSIGN_DIM                                               $4, 'position'
          3        OP_DATA                                                  !0
    6     4        FETCH_IS                                         ~6      '_POST'
          5        ISSET_ISEMPTY_DIM_OBJ                         0  ~7      ~6, 'position'
          6      > JMPZ_EX                                          ~7      ~7, ->11
          7    >   FETCH_R                      global              ~8      '_POST'
          8        FETCH_DIM_R                                      ~9      ~8, 'position'
          9        CAST                                          4  ~10     ~9
         10        BOOL                                             ~7      ~10
         11    > > JMPZ                                                     ~7, ->17
         12    >   FETCH_R                      global              ~11     '_POST'
         13        FETCH_DIM_R                                      ~12     ~11, 'position'
         14        CAST                                          4  ~13     ~12
         15        QM_ASSIGN                                        ~14     ~13
         16      > JMP                                                      ->18
         17    >   QM_ASSIGN                                        ~14     '-1'
         18    >   ASSIGN                                                   !1, ~14
    9    19        FETCH_IS                                         ~16     '_POST'
         20        ISSET_ISEMPTY_DIM_OBJ                         1  ~17     ~16, 'position'
         21        BOOL_NOT                                         ~18     ~17
         22      > JMPZ                                                     ~18, ->28
         23    >   FETCH_R                      global              ~19     '_POST'
         24        FETCH_DIM_R                                      ~20     ~19, 'position'
         25        CAST                                          4  ~21     ~20
         26        QM_ASSIGN                                        ~22     ~21
         27      > JMP                                                      ->29
         28    >   QM_ASSIGN                                        ~22     -1
         29    >   ASSIGN                                                   !2, ~22
   12    30        FETCH_IS                                         ~24     '_POST'
         31        FETCH_DIM_IS                                     ~25     ~24, 'position'
         32        COALESCE                                         ~26     ~25
         33        QM_ASSIGN                                        ~26     '-1'
         34        CAST                                          4  ~27     ~26
         35        ASSIGN                                                   !3, ~27
   14    36        ROPE_INIT                                     3  ~30     'Input%3A+'
         37        ROPE_ADD                                      1  ~30     ~30, !0
         38        ROPE_END                                      2  ~29     ~30, '%0A'
         39        ECHO                                                     ~29
   15    40        ROPE_INIT                                     3  ~33     'Original%3A+'
         41        ROPE_ADD                                      1  ~33     ~33, !1
         42        ROPE_END                                      2  ~32     ~33, '%0A'
         43        ECHO                                                     ~32
   16    44        ROPE_INIT                                     3  ~36     '%21empty%28%29+check%3A+'
         45        ROPE_ADD                                      1  ~36     ~36, !2
         46        ROPE_END                                      2  ~35     ~36, '%0A'
         47        ECHO                                                     ~35
   17    48        ROPE_INIT                                     3  ~39     'Null+coalescing%3A+'
         49        ROPE_ADD                                      1  ~39     ~39, !3
         50        ROPE_END                                      2  ~38     ~39, '%0A'
         51        ECHO                                                     ~38
   18    52        ECHO                                                     '-------------------------%0A'
   19    53      > RETURN                                                   null

End of function test_position

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.85 ms | 1003 KiB | 14 Q