3v4l.org

run code in 300+ PHP versions simultaneously
<?php function buildQuery($retrievables, $table, $conditions = "", $limit = 0, $order = "") { $query = "SELECT $retrievables FROM $table"; // if we have conditions - add them to the query $query .= ($conditions != "" ? " WHERE " . $conditions : ""); // if we have a limit - add it to the query $query .= ($limit != 0 ? " LIMIT " . $limit : ""); // if we have to order the results - add it to the query // first we create a "dictionary" which translates $niceValues that are used throughout the code // to $realValues which are used in the MySQL database // since the $realValues are different in every table - we must account to that switch ($table) { case 'usersTable': $niceValues = ["userID", "userName", "userAge", "userLocation", "userSex", "userIntention", "usersTable"]; $realValues = ["uid", "uname", "user_bdate", "user_from", "name", "user_intrest", "nuke_users"]; // yeah - the field "name" is really the sex of the user break; case 'articlesTable': $niceValues = ["articleID", "articleTitle", "articleLeadingText", "articleBodyText"]; $realValues = ["sid", "title", "hometext", "bodytext"]; break; default: $realValues = []; } // we then replace $niceValues with $realValues $modifiedQuery = str_ireplace($niceValues, $realValues, $query); return $modifiedQuery; } print_r(buildQuery("userID, userAge, userSex", "usersTable", 10)); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/03pWl
function name:  (null)
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   INIT_FCALL                                               'print_r'
          1        INIT_FCALL                                               'buildquery'
          2        SEND_VAL                                                 'userID%2C+userAge%2C+userSex'
          3        SEND_VAL                                                 'usersTable'
          4        SEND_VAL                                                 10
          5        DO_FCALL                                      0  $0      
          6        SEND_VAR                                                 $0
          7        DO_ICALL                                                 
   32     8      > RETURN                                                   1

Function buildquery:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 15
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
4 jumps found. (Code = 188) Position 1 = 30, Position 2 = 33, Position 3 = 36, Position 4 = 25
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 30
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 33
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 33
Branch analysis from position: 30
Branch analysis from position: 22
4 jumps found. (Code = 188) Position 1 = 30, Position 2 = 33, Position 3 = 36, Position 4 = 25
Branch analysis from position: 30
Branch analysis from position: 33
Branch analysis from position: 36
Branch analysis from position: 25
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
Branch analysis from position: 22
filename:       /in/03pWl
function name:  buildQuery
number of ops:  45
compiled vars:  !0 = $retrievables, !1 = $table, !2 = $conditions, !3 = $limit, !4 = $order, !5 = $query, !6 = $niceValues, !7 = $realValues, !8 = $modifiedQuery
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      ''
          3        RECV_INIT                                        !3      0
          4        RECV_INIT                                        !4      ''
    4     5        ROPE_INIT                                     4  ~10     'SELECT+'
          6        ROPE_ADD                                      1  ~10     ~10, !0
          7        ROPE_ADD                                      2  ~10     ~10, '+FROM+'
          8        ROPE_END                                      3  ~9      ~10, !1
          9        ASSIGN                                                   !5, ~9
    6    10        IS_NOT_EQUAL                                             !2, ''
         11      > JMPZ                                                     ~13, ->15
         12    >   CONCAT                                           ~14     '+WHERE+', !2
         13        QM_ASSIGN                                        ~15     ~14
         14      > JMP                                                      ->16
         15    >   QM_ASSIGN                                        ~15     ''
         16    >   ASSIGN_OP                                     8          !5, ~15
    8    17        IS_NOT_EQUAL                                             !3, 0
         18      > JMPZ                                                     ~17, ->22
         19    >   CONCAT                                           ~18     '+LIMIT+', !3
         20        QM_ASSIGN                                        ~19     ~18
         21      > JMP                                                      ->23
         22    >   QM_ASSIGN                                        ~19     ''
         23    >   ASSIGN_OP                                     8          !5, ~19
   14    24      > SWITCH_STRING                                            !1, [ 'usersTable':->30, 'articlesTable':->33, ], ->36
   15    25    >   IS_EQUAL                                                 !1, 'usersTable'
         26      > JMPNZ                                                    ~21, ->30
   19    27    >   IS_EQUAL                                                 !1, 'articlesTable'
         28      > JMPNZ                                                    ~21, ->33
         29    > > JMP                                                      ->36
   16    30    >   ASSIGN                                                   !6, <array>
   17    31        ASSIGN                                                   !7, <array>
   18    32      > JMP                                                      ->37
   20    33    >   ASSIGN                                                   !6, <array>
   21    34        ASSIGN                                                   !7, <array>
   22    35      > JMP                                                      ->37
   24    36    >   ASSIGN                                                   !7, <array>
   27    37    >   INIT_FCALL                                               'str_ireplace'
         38        SEND_VAR                                                 !6
         39        SEND_VAR                                                 !7
         40        SEND_VAR                                                 !5
         41        DO_ICALL                                         $27     
         42        ASSIGN                                                   !8, $27
   29    43      > RETURN                                                   !8
   30    44*     > RETURN                                                   null

End of function buildquery

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.32 ms | 1403 KiB | 18 Q