3v4l.org

run code in 300+ PHP versions simultaneously
<?php function buildQuery($retrievables, $table, $limit = 0, $conditions = "", $orderCondition = "", $orderDirection = "") { $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 $query .= ($orderCondition != "" ? " ORDER BY " . $orderCondition . " " . $orderDirection : ""); // 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 = array("userID", "userName", "userAge", "userLocation", "userSex", "userIntention", "usersTable"); $realValues = array("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 = array("articleID", "articleTitle", "articleLead", "articleBody", "articlesTable"); $realValues = array("sid", "title", "hometext", "bodytext", "nuke_stories"); break; default: $realValues = array(); } // we then replace $niceValues with $realValues $modifiedQuery = str_ireplace($niceValues, $realValues, $query); return $modifiedQuery; } $user = 155566; $userID = (is_string($user) ? 145554 : $user); $retrievables = "uid, user_bdate, user_from, uname, moody"; print_r(buildQuery($retrievables, "usersTable", "", "uid=$userID")); ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XYFKc
function name:  (null)
number of ops:  20
compiled vars:  !0 = $user, !1 = $userID, !2 = $retrievables
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ASSIGN                                                   !0, 155566
   32     1        TYPE_CHECK                                   64          !0
          2      > JMPZ                                                     ~4, ->5
          3    >   QM_ASSIGN                                        ~5      145554
          4      > JMP                                                      ->6
          5    >   QM_ASSIGN                                        ~5      !0
          6    >   ASSIGN                                                   !1, ~5
   33     7        ASSIGN                                                   !2, 'uid%2C+user_bdate%2C+user_from%2C+uname%2C+moody'
   34     8        INIT_FCALL                                               'print_r'
          9        INIT_FCALL                                               'buildquery'
         10        SEND_VAR                                                 !2
         11        SEND_VAL                                                 'usersTable'
         12        SEND_VAL                                                 ''
         13        NOP                                                      
         14        FAST_CONCAT                                      ~8      'uid%3D', !1
         15        SEND_VAL                                                 ~8
         16        DO_FCALL                                      0  $9      
         17        SEND_VAR                                                 $9
         18        DO_ICALL                                                 
   35    19      > RETURN                                                   1

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

End of function buildquery

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.42 ms | 1398 KiB | 18 Q