From: Nikita Popov Date: Mon, 5 Oct 2020 11:06:59 +0000 (+0200) Subject: Update PDO parameter names X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0f3698173e0404d01706d77b10c6d3777eac8225;p=php Update PDO parameter names Followup to previous changes: * Use camel case, as PDO uses a camel case OO API. * Use &$var instead of &$bind_var or &$param. * Use $column instead of $index. We have cases (both inside PDO and in other DB exts) where columns can also be represented as strings, so $column is the safer generic name. Closes GH-6272. --- diff --git a/ext/pdo/pdo_dbh.stub.php b/ext/pdo/pdo_dbh.stub.php index a30d89890c..adca7d6b7a 100644 --- a/ext/pdo/pdo_dbh.stub.php +++ b/ext/pdo/pdo_dbh.stub.php @@ -34,10 +34,10 @@ class PDO public function lastInsertId(?string $name = null) {} /** @return PDOStatement|false */ - public function prepare(string $query, array $driver_options = []) {} + public function prepare(string $query, array $options = []) {} /** @return PDOStatement|false */ - public function query(string $query, ?int $fetch_mode = null, mixed ...$fetch_mode_args) {} + public function query(string $query, ?int $fetchMode = null, mixed ...$fetchModeArgs) {} /** @return string|false */ public function quote(string $string, int $type = PDO::PARAM_STR) {} diff --git a/ext/pdo/pdo_dbh_arginfo.h b/ext/pdo/pdo_dbh_arginfo.h index ffeb1c9eeb..ac2fc76350 100644 --- a/ext/pdo/pdo_dbh_arginfo.h +++ b/ext/pdo/pdo_dbh_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 2bee02a9952faf3f768873bafe1be9ef89086029 */ + * Stub hash: 788d1cd616c140df4072c6e0564c2995fbdc84ad */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO___construct, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, dsn, IS_STRING, 0) @@ -35,13 +35,13 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO_prepare, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, query, IS_STRING, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, driver_options, IS_ARRAY, 0, "[]") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 0, "[]") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO_query, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, query, IS_STRING, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, fetch_mode, IS_LONG, 1, "null") - ZEND_ARG_VARIADIC_TYPE_INFO(0, fetch_mode_args, IS_MIXED, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, fetchMode, IS_LONG, 1, "null") + ZEND_ARG_VARIADIC_TYPE_INFO(0, fetchModeArgs, IS_MIXED, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO_quote, 0, 0, 1) diff --git a/ext/pdo/pdo_stmt.stub.php b/ext/pdo/pdo_stmt.stub.php index eccd22d7d9..06d6a557e7 100644 --- a/ext/pdo/pdo_stmt.stub.php +++ b/ext/pdo/pdo_stmt.stub.php @@ -5,10 +5,10 @@ class PDOStatement implements IteratorAggregate { /** @return bool */ - public function bindColumn(string|int $column, mixed &$param, int $type = 0, int $max_length = 0, mixed $driver_options = null) {} + public function bindColumn(string|int $column, mixed &$var, int $type = 0, int $maxLength = 0, mixed $driverOptions = null) {} /** @return bool */ - public function bindParam(string|int $param, mixed &$bind_var, int $type = PDO::PARAM_STR, int $max_length = 0, mixed $driver_options = null) {} + public function bindParam(string|int $param, mixed &$var, int $type = PDO::PARAM_STR, int $maxLength = 0, mixed $driverOptions = null) {} /** @return bool */ public function bindValue(string|int $param, mixed $value, int $type = PDO::PARAM_STR) {} @@ -29,25 +29,25 @@ class PDOStatement implements IteratorAggregate public function errorInfo() {} /** @return bool */ - public function execute(?array $input_parameters = null) {} + public function execute(?array $params = null) {} /** @return mixed */ - public function fetch(int $mode = PDO::FETCH_BOTH, int $cursor_orientation = PDO::FETCH_ORI_NEXT, int $cursor_offset = 0) {} + public function fetch(int $mode = PDO::FETCH_BOTH, int $cursorOrientation = PDO::FETCH_ORI_NEXT, int $cursorOffset = 0) {} /** @return array */ public function fetchAll(int $mode = PDO::FETCH_BOTH, mixed ...$args) {} /** @return mixed */ - public function fetchColumn(int $index = 0) {} + public function fetchColumn(int $column = 0) {} /** @return mixed */ - public function fetchObject(?string $class = "stdClass", ?array $constructor_args = null) {} + public function fetchObject(?string $class = "stdClass", ?array $ctorArgs = null) {} /** @return mixed */ public function getAttribute(int $name) {} /** @return array|false */ - public function getColumnMeta(int $index) {} + public function getColumnMeta(int $column) {} /** @return bool */ public function nextRowset() {} @@ -59,7 +59,7 @@ class PDOStatement implements IteratorAggregate public function setAttribute(int $attribute, mixed $value) {} /** @return bool */ - public function setFetchMode(int $mode, mixed ...$fetch_mode_args) {} + public function setFetchMode(int $mode, mixed ...$args) {} public function getIterator(): Iterator {} } diff --git a/ext/pdo/pdo_stmt_arginfo.h b/ext/pdo/pdo_stmt_arginfo.h index f55c1ea848..9e7eea4c3b 100644 --- a/ext/pdo/pdo_stmt_arginfo.h +++ b/ext/pdo/pdo_stmt_arginfo.h @@ -1,20 +1,20 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: b3338fc077eab1280da093f059fac14dd7f19678 */ + * Stub hash: 574055f1dbb6a1bee10e4476642a759e53ca2802 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_bindColumn, 0, 0, 2) ZEND_ARG_TYPE_MASK(0, column, MAY_BE_STRING|MAY_BE_LONG, NULL) - ZEND_ARG_TYPE_INFO(1, param, IS_MIXED, 0) + ZEND_ARG_TYPE_INFO(1, var, IS_MIXED, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, type, IS_LONG, 0, "0") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, max_length, IS_LONG, 0, "0") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, driver_options, IS_MIXED, 0, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, maxLength, IS_LONG, 0, "0") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, driverOptions, IS_MIXED, 0, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_bindParam, 0, 0, 2) ZEND_ARG_TYPE_MASK(0, param, MAY_BE_STRING|MAY_BE_LONG, NULL) - ZEND_ARG_TYPE_INFO(1, bind_var, IS_MIXED, 0) + ZEND_ARG_TYPE_INFO(1, var, IS_MIXED, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, type, IS_LONG, 0, "PDO::PARAM_STR") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, max_length, IS_LONG, 0, "0") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, driver_options, IS_MIXED, 0, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, maxLength, IS_LONG, 0, "0") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, driverOptions, IS_MIXED, 0, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_bindValue, 0, 0, 2) @@ -35,13 +35,13 @@ ZEND_END_ARG_INFO() #define arginfo_class_PDOStatement_errorInfo arginfo_class_PDOStatement_closeCursor ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_execute, 0, 0, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, input_parameters, IS_ARRAY, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, params, IS_ARRAY, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_fetch, 0, 0, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "PDO::FETCH_BOTH") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, cursor_orientation, IS_LONG, 0, "PDO::FETCH_ORI_NEXT") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, cursor_offset, IS_LONG, 0, "0") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, cursorOrientation, IS_LONG, 0, "PDO::FETCH_ORI_NEXT") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, cursorOffset, IS_LONG, 0, "0") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_fetchAll, 0, 0, 0) @@ -50,12 +50,12 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_fetchAll, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_fetchColumn, 0, 0, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, index, IS_LONG, 0, "0") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, column, IS_LONG, 0, "0") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_fetchObject, 0, 0, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, class, IS_STRING, 1, "\"stdClass\"") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, constructor_args, IS_ARRAY, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, ctorArgs, IS_ARRAY, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_getAttribute, 0, 0, 1) @@ -63,7 +63,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_getAttribute, 0, 0, 1) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_getColumnMeta, 0, 0, 1) - ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, column, IS_LONG, 0) ZEND_END_ARG_INFO() #define arginfo_class_PDOStatement_nextRowset arginfo_class_PDOStatement_closeCursor @@ -77,7 +77,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_setFetchMode, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, mode, IS_LONG, 0) - ZEND_ARG_VARIADIC_TYPE_INFO(0, fetch_mode_args, IS_MIXED, 0) + ZEND_ARG_VARIADIC_TYPE_INFO(0, args, IS_MIXED, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_PDOStatement_getIterator, 0, 0, Iterator, 0) diff --git a/ext/pdo/tests/bug_44173.phpt b/ext/pdo/tests/bug_44173.phpt index 0baa7973e5..1b59d5590f 100644 --- a/ext/pdo/tests/bug_44173.phpt +++ b/ext/pdo/tests/bug_44173.phpt @@ -73,7 +73,7 @@ try { ?> --EXPECT-- PDO::query() expects exactly 2 arguments for the fetch mode provided, 4 given -PDO::query(): Argument #2 ($fetch_mode) must be of type ?int, string given +PDO::query(): Argument #2 ($fetchMode) must be of type ?int, string given PDO::query() expects at most 4 arguments for the fetch mode provided, 5 given PDO::query() expects exactly 3 arguments for the fetch mode provided, 2 given PDO::query() expects exactly 3 arguments for the fetch mode provided, 2 given diff --git a/ext/pdo_mysql/tests/bug_37445.phpt b/ext/pdo_mysql/tests/bug_37445.phpt index ca321443e3..834950fd48 100644 --- a/ext/pdo_mysql/tests/bug_37445.phpt +++ b/ext/pdo_mysql/tests/bug_37445.phpt @@ -17,7 +17,7 @@ $stmt = $db->prepare("SELECT 1"); $stmt->bindParam(':a', 'b'); ?> --EXPECTF-- -Fatal error: Uncaught Error: PDOStatement::bindParam(): Argument #2 ($bind_var) cannot be passed by reference in %sbug_37445.php:%d +Fatal error: Uncaught Error: PDOStatement::bindParam(): Argument #2 ($var) cannot be passed by reference in %sbug_37445.php:%d Stack trace: #0 {main} thrown in %sbug_37445.php on line %d diff --git a/ext/pdo_mysql/tests/pdo_mysql_stmt_getcolumnmeta.phpt b/ext/pdo_mysql/tests/pdo_mysql_stmt_getcolumnmeta.phpt index 61734061d9..b5b0275f04 100644 --- a/ext/pdo_mysql/tests/pdo_mysql_stmt_getcolumnmeta.phpt +++ b/ext/pdo_mysql/tests/pdo_mysql_stmt_getcolumnmeta.phpt @@ -302,6 +302,6 @@ $db->exec('DROP TABLE IF EXISTS test'); print "done!"; ?> --EXPECT-- -PDOStatement::getColumnMeta(): Argument #1 ($index) must be greater than or equal to 0 +PDOStatement::getColumnMeta(): Argument #1 ($column) must be greater than or equal to 0 Testing native PS... done!