3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types = 1); namespace at\PDOi; use PDO as BasePDO, PDOStatement; $pdo = new PDO('sqlite::memory:'); [$markers, $values] = $pdo->arrayParam(['a', 'b', 'c']); $stmt = $pdo->prepare("select 'a' IN ({$markers})"); $stmt->execute($values); var_dump($stmt->fetch(PDO::FETCH_ASSOC)); [$markers, $values] = $pdo->arrayParam(['a', 'b', 'c'], 'letters'); $stmt = $pdo->prepare("select 'a' IN ({$markers})"); $stmt->execute($values); var_dump($stmt->fetch(PDO::FETCH_ASSOC)); /** * @package at.pdoi * @author Adrian <adrian@enspi.red> * @copyright 2014 - 2017 * @license GPL-3.0 (only) * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License, version 3. * The right to apply the terms of later versions of the GPL is RESERVED. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. * If not, see <http://www.gnu.org/licenses/gpl-3.0.txt>. */ /** * minor changes and additions to enhance PDO's security and convenience. */ class PDO extends BasePDO { /** * {@inheritDoc} * @see http://php.net/PDO.__construct * * adds good default options. */ public function __construct($dsn, $username = null, $password = null, $options = []) { $options += [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false ]; parent::__construct($dsn, $username, $password, $options); } /** * expands arrays into multiple named or positional parameters. * * @param array $values the values to parameterize * @param string $name name for named parameters (omit for positional parameters) * @return array { * @type string $0 comma-separated parameter markers (sql fragment) * @type array $1 parameter values, as a map or ordered list * } */ public function arrayParam(array $values, string $name = null) { $values = array_values($values); $i = 0; $keys = array_map( function ($value) use ($name, &$i) { $marker = $name ? ":{$name}_{$i}" : '?'; $i++; return $marker; }, $values ); if ($name) { $values = array_combine($keys, $values); } return [implode(', ', $keys), $values]; } /** * prepares and executes a statement in one step. * * @param string $sql the sql statement to prepare * @param array $params parameter values to execute against the statement * @return PDOStatement the executed statement object on success */ public function preparedQuery(string $sql, array $params = []) : PDOStatement { $stmt = $this->prepare($sql); $stmt->execute($params); return $stmt; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QmVRI
function name:  (null)
number of ops:  56
compiled vars:  !0 = $pdo, !1 = $markers, !2 = $values, !3 = $stmt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   NEW                                              $4      'at%5CPDOi%5CPDO'
          1        SEND_VAL_EX                                              'sqlite%3A%3Amemory%3A'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $4
   10     4        INIT_METHOD_CALL                                         !0, 'arrayParam'
          5        SEND_VAL_EX                                              <array>
          6        DO_FCALL                                      0  $7      
          7        FETCH_LIST_R                                     $8      $7, 0
          8        ASSIGN                                                   !1, $8
          9        FETCH_LIST_R                                     $10     $7, 1
         10        ASSIGN                                                   !2, $10
         11        FREE                                                     $7
   11    12        INIT_METHOD_CALL                                         !0, 'prepare'
         13        ROPE_INIT                                     3  ~13     'select+%27a%27+IN+%28'
         14        ROPE_ADD                                      1  ~13     ~13, !1
         15        ROPE_END                                      2  ~12     ~13, '%29'
         16        SEND_VAL_EX                                              ~12
         17        DO_FCALL                                      0  $15     
         18        ASSIGN                                                   !3, $15
   12    19        INIT_METHOD_CALL                                         !3, 'execute'
         20        SEND_VAR_EX                                              !2
         21        DO_FCALL                                      0          
   14    22        INIT_NS_FCALL_BY_NAME                                    'at%5CPDOi%5Cvar_dump'
         23        INIT_METHOD_CALL                                         !3, 'fetch'
         24        FETCH_CLASS_CONSTANT                             ~18     'at%5CPDOi%5CPDO', 'FETCH_ASSOC'
         25        SEND_VAL_EX                                              ~18
         26        DO_FCALL                                      0  $19     
         27        SEND_VAR_NO_REF_EX                                       $19
         28        DO_FCALL                                      0          
   17    29        INIT_METHOD_CALL                                         !0, 'arrayParam'
         30        SEND_VAL_EX                                              <array>
         31        SEND_VAL_EX                                              'letters'
         32        DO_FCALL                                      0  $21     
         33        FETCH_LIST_R                                     $22     $21, 0
         34        ASSIGN                                                   !1, $22
         35        FETCH_LIST_R                                     $24     $21, 1
         36        ASSIGN                                                   !2, $24
         37        FREE                                                     $21
   18    38        INIT_METHOD_CALL                                         !0, 'prepare'
         39        ROPE_INIT                                     3  ~27     'select+%27a%27+IN+%28'
         40        ROPE_ADD                                      1  ~27     ~27, !1
         41        ROPE_END                                      2  ~26     ~27, '%29'
         42        SEND_VAL_EX                                              ~26
         43        DO_FCALL                                      0  $29     
         44        ASSIGN                                                   !3, $29
   19    45        INIT_METHOD_CALL                                         !3, 'execute'
         46        SEND_VAR_EX                                              !2
         47        DO_FCALL                                      0          
   21    48        INIT_NS_FCALL_BY_NAME                                    'at%5CPDOi%5Cvar_dump'
         49        INIT_METHOD_CALL                                         !3, 'fetch'
         50        FETCH_CLASS_CONSTANT                             ~32     'at%5CPDOi%5CPDO', 'FETCH_ASSOC'
         51        SEND_VAL_EX                                              ~32
         52        DO_FCALL                                      0  $33     
         53        SEND_VAR_NO_REF_EX                                       $33
         54        DO_FCALL                                      0          
  102    55      > RETURN                                                   1

Function %00at%5Cpdoi%5C%7Bclosure%7D%2Fin%2FQmVRI%3A75%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QmVRI
function name:  at\PDOi\{closure}
number of ops:  15
compiled vars:  !0 = $value, !1 = $name, !2 = $i, !3 = $marker
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   75     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   76     3      > JMPZ                                                     !1, ->10
          4    >   ROPE_INIT                                     4  ~5      '%3A'
          5        ROPE_ADD                                      1  ~5      ~5, !1
          6        ROPE_ADD                                      2  ~5      ~5, '_'
          7        ROPE_END                                      3  ~4      ~5, !2
          8        QM_ASSIGN                                        ~7      ~4
          9      > JMP                                                      ->11
         10    >   QM_ASSIGN                                        ~7      '%3F'
         11    >   ASSIGN                                                   !3, ~7
   77    12        PRE_INC                                                  !2
   78    13      > RETURN                                                   !3
   79    14*     > RETURN                                                   null

End of function %00at%5Cpdoi%5C%7Bclosure%7D%2Fin%2FQmVRI%3A75%240

Class at\PDOi\PDO:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QmVRI
function name:  __construct
number of ops:  17
compiled vars:  !0 = $dsn, !1 = $username, !2 = $password, !3 = $options
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
          2        RECV_INIT                                        !2      null
          3        RECV_INIT                                        !3      <array>
   55     4        FETCH_CLASS_CONSTANT                             ~4      'at%5CPDOi%5CPDO', 'ATTR_ERRMODE'
          5        FETCH_CLASS_CONSTANT                             ~5      'at%5CPDOi%5CPDO', 'ERRMODE_EXCEPTION'
          6        INIT_ARRAY                                       ~6      ~5, ~4
   56     7        FETCH_CLASS_CONSTANT                             ~7      'at%5CPDOi%5CPDO', 'ATTR_EMULATE_PREPARES'
   55     8        ADD_ARRAY_ELEMENT                                ~6      <false>, ~7
          9        ASSIGN_OP                                     1          !3, ~6
   58    10        INIT_STATIC_METHOD_CALL                                  
         11        SEND_VAR_EX                                              !0
         12        SEND_VAR_EX                                              !1
         13        SEND_VAR_EX                                              !2
         14        SEND_VAR_EX                                              !3
         15        DO_FCALL                                      0          
   59    16      > RETURN                                                   null

End of function __construct

Function arrayparam:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 21
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/QmVRI
function name:  arrayParam
number of ops:  29
compiled vars:  !0 = $values, !1 = $name, !2 = $i, !3 = $keys
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   71     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   72     2        INIT_NS_FCALL_BY_NAME                                    'at%5CPDOi%5Carray_values'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $4      
          5        ASSIGN                                                   !0, $4
   73     6        ASSIGN                                                   !2, 0
   74     7        INIT_NS_FCALL_BY_NAME                                    'at%5CPDOi%5Carray_map'
   75     8        DECLARE_LAMBDA_FUNCTION                                  '%00at%5Cpdoi%5C%7Bclosure%7D%2Fin%2FQmVRI%3A75%240'
          9        BIND_LEXICAL                                             ~7, !1
         10        BIND_LEXICAL                                             ~7, !2
   79    11        SEND_VAL_EX                                              ~7
   75    12        SEND_VAR_EX                                              !0
         13        DO_FCALL                                      0  $8      
   74    14        ASSIGN                                                   !3, $8
   83    15      > JMPZ                                                     !1, ->21
   84    16    >   INIT_NS_FCALL_BY_NAME                                    'at%5CPDOi%5Carray_combine'
         17        SEND_VAR_EX                                              !3
         18        SEND_VAR_EX                                              !0
         19        DO_FCALL                                      0  $10     
         20        ASSIGN                                                   !0, $10
   87    21    >   INIT_NS_FCALL_BY_NAME                                    'at%5CPDOi%5Cimplode'
         22        SEND_VAL_EX                                              '%2C+'
         23        SEND_VAR_EX                                              !3
         24        DO_FCALL                                      0  $12     
         25        INIT_ARRAY                                       ~13     $12
         26        ADD_ARRAY_ELEMENT                                ~13     !0
         27      > RETURN                                                   ~13
   88    28*     > RETURN                                                   null

End of function arrayparam

Function preparedquery:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QmVRI
function name:  preparedQuery
number of ops:  13
compiled vars:  !0 = $sql, !1 = $params, !2 = $stmt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   97     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
   98     2        INIT_METHOD_CALL                                         'prepare'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $3      
          5        ASSIGN                                                   !2, $3
   99     6        INIT_METHOD_CALL                                         !2, 'execute'
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0          
  100     9        VERIFY_RETURN_TYPE                                       !2
         10      > RETURN                                                   !2
  101    11*       VERIFY_RETURN_TYPE                                       
         12*     > RETURN                                                   null

End of function preparedquery

End of class at\PDOi\PDO.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171 ms | 1408 KiB | 23 Q