3v4l.org

run code in 300+ PHP versions simultaneously
<?php class NamedInClause { public $data; public $clause; public function __construct(array $array, $name = 'in') { $placeholders = array(); $i = 0; $name = preg_replace('/[^a-z0-9_]+/', '', (string)$name); if (!preg_match('/^[a-z]/i', $name)) { throw new \InvalidArgumentException('Placeholder name ' . $name . ': must begin with a letter'); } foreach ($array as $value) { $key = $name . $i++; $placeholders[] = ':' . $key; $this->data[$key] = $value; } $this->string = implode(', ', $placeholders); } } $inClause = new NamedInClause([1, 2, 3], 'id'); // Build the query string $query = " UPDATE table SET value1 = :val1, value2 = :val2 WHERE id IN (" . $inClause->clause . ") "; // Create the data array. Get an array of concrete values and merge the IN clause data $data = array('val1' => 'Hello', 'val2' => 'World') + $inClause->data; var_dump($query, $data); /* $stmt = $db->prepare($query); $stmt->execute($data); */
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/S4fEd
function name:  (null)
number of ops:  17
compiled vars:  !0 = $inClause, !1 = $query, !2 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   NEW                                              $3      'NamedInClause'
          1        SEND_VAL_EX                                              <array>
          2        SEND_VAL_EX                                              'id'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $3
   34     5        FETCH_OBJ_R                                      ~6      !0, 'clause'
          6        CONCAT                                           ~7      '%0A++UPDATE+table%0A++SET+value1+%3D+%3Aval1%2C+value2+%3D+%3Aval2%0A++WHERE+id+IN+%28', ~6
          7        CONCAT                                           ~8      ~7, '%29%0A'
   31     8        ASSIGN                                                   !1, ~8
   38     9        FETCH_OBJ_R                                      ~10     !0, 'data'
         10        ADD                                              ~11     <array>, ~10
         11        ASSIGN                                                   !2, ~11
   40    12        INIT_FCALL                                               'var_dump'
         13        SEND_VAR                                                 !1
         14        SEND_VAR                                                 !2
         15        DO_ICALL                                                 
   45    16      > RETURN                                                   1

Class NamedInClause:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 23
Branch analysis from position: 17
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 23
2 jumps found. (Code = 77) Position 1 = 24, Position 2 = 35
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 35
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/S4fEd
function name:  __construct
number of ops:  43
compiled vars:  !0 = $array, !1 = $name, !2 = $placeholders, !3 = $i, !4 = $value, !5 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      'in'
    9     2        ASSIGN                                                   !2, <array>
   10     3        ASSIGN                                                   !3, 0
   12     4        INIT_FCALL                                               'preg_replace'
          5        SEND_VAL                                                 '%2F%5B%5Ea-z0-9_%5D%2B%2F'
          6        SEND_VAL                                                 ''
          7        CAST                                          6  ~8      !1
          8        SEND_VAL                                                 ~8
          9        DO_ICALL                                         $9      
         10        ASSIGN                                                   !1, $9
   13    11        INIT_FCALL                                               'preg_match'
         12        SEND_VAL                                                 '%2F%5E%5Ba-z%5D%2Fi'
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                         $11     
         15        BOOL_NOT                                         ~12     $11
         16      > JMPZ                                                     ~12, ->23
   14    17    >   NEW                                              $13     'InvalidArgumentException'
         18        CONCAT                                           ~14     'Placeholder+name+', !1
         19        CONCAT                                           ~15     ~14, '%3A+must+begin+with+a+letter'
         20        SEND_VAL_EX                                              ~15
         21        DO_FCALL                                      0          
         22      > THROW                                         0          $13
   17    23    > > FE_RESET_R                                       $17     !0, ->35
         24    > > FE_FETCH_R                                               $17, !4, ->35
   18    25    >   POST_INC                                         ~18     !3
         26        CONCAT                                           ~19     !1, ~18
         27        ASSIGN                                                   !5, ~19
   19    28        CONCAT                                           ~22     '%3A', !5
         29        ASSIGN_DIM                                               !2
         30        OP_DATA                                                  ~22
   20    31        FETCH_OBJ_W                                      $23     'data'
         32        ASSIGN_DIM                                               $23, !5
         33        OP_DATA                                                  !4
   17    34      > JMP                                                      ->24
         35    >   FE_FREE                                                  $17
   23    36        INIT_FCALL                                               'implode'
         37        SEND_VAL                                                 '%2C+'
         38        SEND_VAR                                                 !2
         39        DO_ICALL                                         $26     
         40        ASSIGN_OBJ                                               'string'
         41        OP_DATA                                                  $26
   24    42      > RETURN                                                   null

End of function __construct

End of class NamedInClause.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.5 ms | 1392 KiB | 21 Q