diff --git a/UPGRADE.md b/UPGRADE.md index f01959459a7..4d6dc59053c 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -8,6 +8,11 @@ awareness about deprecated code. # Upgrade to 3.4 +## Deprecated not passing parameter type to `Statement::bind*()` methods. + +Not passing `$type` to `Statement::bindParam()` and `::bindValue()` is deprecated. Pass the type +corresponding to the parameter being bound. + ## Deprecated passing `$params` to `Statement::execute*()` methods. Passing `$params` to the driver-level `Statement::execute()` and the wrapper-level `Statement::executeQuery()` diff --git a/src/Connection.php b/src/Connection.php index 67530dadca0..f587b6207cd 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -1671,7 +1671,6 @@ private function bindParameters(DriverStatement $stmt, array $params, array $typ if (isset($types[$key])) { $type = $types[$key]; [$value, $bindingType] = $this->getBindingInfo($value, $type); - $stmt->bindValue($bindIndex, $value, $bindingType); } else { if (array_key_exists($key, $types)) { Deprecation::trigger( @@ -1682,9 +1681,11 @@ private function bindParameters(DriverStatement $stmt, array $params, array $typ ); } - $stmt->bindValue($bindIndex, $value); + $bindingType = ParameterType::STRING; } + $stmt->bindValue($bindIndex, $value, $bindingType); + ++$bindIndex; } } else { @@ -1693,7 +1694,6 @@ private function bindParameters(DriverStatement $stmt, array $params, array $typ if (isset($types[$name])) { $type = $types[$name]; [$value, $bindingType] = $this->getBindingInfo($value, $type); - $stmt->bindValue($name, $value, $bindingType); } else { if (array_key_exists($name, $types)) { Deprecation::trigger( @@ -1704,8 +1704,10 @@ private function bindParameters(DriverStatement $stmt, array $params, array $typ ); } - $stmt->bindValue($name, $value); + $bindingType = ParameterType::STRING; } + + $stmt->bindValue($name, $value, $bindingType); } } } diff --git a/src/Driver/IBMDB2/Statement.php b/src/Driver/IBMDB2/Statement.php index 5642ec98e37..02bdd989196 100644 --- a/src/Driver/IBMDB2/Statement.php +++ b/src/Driver/IBMDB2/Statement.php @@ -16,6 +16,7 @@ use function db2_execute; use function error_get_last; use function fclose; +use function func_num_args; use function is_int; use function is_resource; use function stream_copy_to_stream; @@ -61,6 +62,15 @@ public function bindValue($param, $value, $type = ParameterType::STRING): bool { assert(is_int($param)); + if (func_num_args() < 3) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5558', + 'Not passing $type to Statement::bindValue() is deprecated.' + . ' Pass the type corresponding to the parameter being bound.' + ); + } + return $this->bindParam($param, $value, $type); } @@ -71,6 +81,15 @@ public function bindParam($param, &$variable, $type = ParameterType::STRING, $le { assert(is_int($param)); + if (func_num_args() < 3) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5558', + 'Not passing $type to Statement::bindParam() is deprecated.' + . ' Pass the type corresponding to the parameter being bound.' + ); + } + switch ($type) { case ParameterType::INTEGER: $this->bind($param, $variable, DB2_PARAM_IN, DB2_LONG); diff --git a/src/Driver/Middleware/AbstractStatementMiddleware.php b/src/Driver/Middleware/AbstractStatementMiddleware.php index 3a3dc524eef..fba62cd6ed7 100644 --- a/src/Driver/Middleware/AbstractStatementMiddleware.php +++ b/src/Driver/Middleware/AbstractStatementMiddleware.php @@ -5,6 +5,9 @@ use Doctrine\DBAL\Driver\Result; use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\ParameterType; +use Doctrine\Deprecations\Deprecation; + +use function func_num_args; abstract class AbstractStatementMiddleware implements Statement { @@ -20,6 +23,15 @@ public function __construct(Statement $wrappedStatement) */ public function bindValue($param, $value, $type = ParameterType::STRING) { + if (func_num_args() < 3) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5558', + 'Not passing $type to Statement::bindValue() is deprecated.' + . ' Pass the type corresponding to the parameter being bound.' + ); + } + return $this->wrappedStatement->bindValue($param, $value, $type); } @@ -28,6 +40,15 @@ public function bindValue($param, $value, $type = ParameterType::STRING) */ public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null) { + if (func_num_args() < 3) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5558', + 'Not passing $type to Statement::bindParam() is deprecated.' + . ' Pass the type corresponding to the parameter being bound.' + ); + } + return $this->wrappedStatement->bindParam($param, $variable, $type, $length); } diff --git a/src/Driver/Mysqli/Statement.php b/src/Driver/Mysqli/Statement.php index d619a7164d9..8365ee1e68f 100644 --- a/src/Driver/Mysqli/Statement.php +++ b/src/Driver/Mysqli/Statement.php @@ -19,6 +19,7 @@ use function count; use function feof; use function fread; +use function func_num_args; use function get_resource_type; use function is_int; use function is_resource; @@ -70,6 +71,15 @@ public function bindParam($param, &$variable, $type = ParameterType::STRING, $le { assert(is_int($param)); + if (func_num_args() < 3) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5558', + 'Not passing $type to Statement::bindParam() is deprecated.' + . ' Pass the type corresponding to the parameter being bound.' + ); + } + if (! isset(self::$paramTypeMap[$type])) { throw UnknownParameterType::new($type); } @@ -87,6 +97,15 @@ public function bindValue($param, $value, $type = ParameterType::STRING): bool { assert(is_int($param)); + if (func_num_args() < 3) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5558', + 'Not passing $type to Statement::bindValue() is deprecated.' + . ' Pass the type corresponding to the parameter being bound.' + ); + } + if (! isset(self::$paramTypeMap[$type])) { throw UnknownParameterType::new($type); } diff --git a/src/Driver/OCI8/Statement.php b/src/Driver/OCI8/Statement.php index 9d65234119e..1d5bd9584ca 100644 --- a/src/Driver/OCI8/Statement.php +++ b/src/Driver/OCI8/Statement.php @@ -9,6 +9,7 @@ use Doctrine\DBAL\ParameterType; use Doctrine\Deprecations\Deprecation; +use function func_num_args; use function is_int; use function oci_bind_by_name; use function oci_execute; @@ -55,6 +56,15 @@ public function __construct($connection, $statement, array $parameterMap, Execut */ public function bindValue($param, $value, $type = ParameterType::STRING): bool { + if (func_num_args() < 3) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5558', + 'Not passing $type to Statement::bindValue() is deprecated.' + . ' Pass the type corresponding to the parameter being bound.' + ); + } + return $this->bindParam($param, $value, $type); } @@ -63,6 +73,15 @@ public function bindValue($param, $value, $type = ParameterType::STRING): bool */ public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null): bool { + if (func_num_args() < 3) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5558', + 'Not passing $type to Statement::bindParam() is deprecated.' + . ' Pass the type corresponding to the parameter being bound.' + ); + } + if (is_int($param)) { if (! isset($this->parameterMap[$param])) { throw UnknownParameterIndex::new($param); @@ -123,9 +142,9 @@ public function execute($params = null): ResultInterface foreach ($params as $key => $val) { if (is_int($key)) { - $this->bindValue($key + 1, $val); + $this->bindValue($key + 1, $val, ParameterType::STRING); } else { - $this->bindValue($key, $val); + $this->bindValue($key, $val, ParameterType::STRING); } } } diff --git a/src/Driver/PDO/SQLSrv/Statement.php b/src/Driver/PDO/SQLSrv/Statement.php index 862aefbb509..80e018d5494 100644 --- a/src/Driver/PDO/SQLSrv/Statement.php +++ b/src/Driver/PDO/SQLSrv/Statement.php @@ -40,6 +40,15 @@ public function bindParam( $length = null, $driverOptions = null ): bool { + if (func_num_args() < 3) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5558', + 'Not passing $type to Statement::bindParam() is deprecated.' + . ' Pass the type corresponding to the parameter being bound.' + ); + } + if (func_num_args() > 4) { Deprecation::triggerIfCalledFromOutside( 'doctrine/dbal', @@ -70,6 +79,15 @@ public function bindParam( */ public function bindValue($param, $value, $type = ParameterType::STRING): bool { + if (func_num_args() < 3) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5558', + 'Not passing $type to Statement::bindValue() is deprecated.' + . ' Pass the type corresponding to the parameter being bound.' + ); + } + return $this->bindParam($param, $value, $type); } } diff --git a/src/Driver/PDO/Statement.php b/src/Driver/PDO/Statement.php index aae7c68408e..497bc5e24e8 100644 --- a/src/Driver/PDO/Statement.php +++ b/src/Driver/PDO/Statement.php @@ -43,6 +43,15 @@ public function __construct(PDOStatement $stmt) */ public function bindValue($param, $value, $type = ParameterType::STRING) { + if (func_num_args() < 3) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5558', + 'Not passing $type to Statement::bindValue() is deprecated.' + . ' Pass the type corresponding to the parameter being bound.' + ); + } + $type = $this->convertParamType($type); try { @@ -68,6 +77,15 @@ public function bindParam( $length = null, $driverOptions = null ): bool { + if (func_num_args() < 3) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5558', + 'Not passing $type to Statement::bindParam() is deprecated.' + . ' Pass the type corresponding to the parameter being bound.' + ); + } + if (func_num_args() > 4) { Deprecation::triggerIfCalledFromOutside( 'doctrine/dbal', diff --git a/src/Driver/SQLSrv/Statement.php b/src/Driver/SQLSrv/Statement.php index 09c34e920a6..2d7c1c6040a 100644 --- a/src/Driver/SQLSrv/Statement.php +++ b/src/Driver/SQLSrv/Statement.php @@ -10,6 +10,7 @@ use Doctrine\Deprecations\Deprecation; use function assert; +use function func_num_args; use function is_int; use function sqlsrv_execute; use function SQLSRV_PHPTYPE_STREAM; @@ -87,6 +88,15 @@ public function bindValue($param, $value, $type = ParameterType::STRING): bool { assert(is_int($param)); + if (func_num_args() < 3) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5558', + 'Not passing $type to Statement::bindValue() is deprecated.' + . ' Pass the type corresponding to the parameter being bound.' + ); + } + $this->variables[$param] = $value; $this->types[$param] = $type; @@ -100,6 +110,15 @@ public function bindParam($param, &$variable, $type = ParameterType::STRING, $le { assert(is_int($param)); + if (func_num_args() < 3) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5558', + 'Not passing $type to Statement::bindParam() is deprecated.' + . ' Pass the type corresponding to the parameter being bound.' + ); + } + $this->variables[$param] =& $variable; $this->types[$param] = $type; @@ -124,9 +143,9 @@ public function execute($params = null): ResultInterface foreach ($params as $key => $val) { if (is_int($key)) { - $this->bindValue($key + 1, $val); + $this->bindValue($key + 1, $val, ParameterType::STRING); } else { - $this->bindValue($key, $val); + $this->bindValue($key, $val, ParameterType::STRING); } } } diff --git a/src/Logging/Statement.php b/src/Logging/Statement.php index 8824d7d4f20..672f5647cc7 100644 --- a/src/Logging/Statement.php +++ b/src/Logging/Statement.php @@ -8,10 +8,12 @@ use Doctrine\DBAL\Driver\Result as ResultInterface; use Doctrine\DBAL\Driver\Statement as StatementInterface; use Doctrine\DBAL\ParameterType; +use Doctrine\Deprecations\Deprecation; use Psr\Log\LoggerInterface; use function array_slice; use function func_get_args; +use function func_num_args; final class Statement extends AbstractStatementMiddleware { @@ -40,6 +42,15 @@ public function __construct(StatementInterface $statement, LoggerInterface $logg */ public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null) { + if (func_num_args() < 3) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5558', + 'Not passing $type to Statement::bindParam() is deprecated.' + . ' Pass the type corresponding to the parameter being bound.' + ); + } + $this->params[$param] = &$variable; $this->types[$param] = $type; @@ -51,6 +62,15 @@ public function bindParam($param, &$variable, $type = ParameterType::STRING, $le */ public function bindValue($param, $value, $type = ParameterType::STRING) { + if (func_num_args() < 3) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5558', + 'Not passing $type to Statement::bindValue() is deprecated.' + . ' Pass the type corresponding to the parameter being bound.' + ); + } + $this->params[$param] = $value; $this->types[$param] = $type; diff --git a/src/Statement.php b/src/Statement.php index 39a33f33e10..ef33a033600 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -93,6 +93,15 @@ public function __construct(Connection $conn, Driver\Statement $statement, strin */ public function bindValue($param, $value, $type = ParameterType::STRING) { + if (func_num_args() < 3) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5558', + 'Not passing $type to Statement::bindValue() is deprecated.' + . ' Pass the type corresponding to the parameter being bound.' + ); + } + $this->params[$param] = $value; $this->types[$param] = $type; @@ -135,6 +144,15 @@ public function bindValue($param, $value, $type = ParameterType::STRING) */ public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null) { + if (func_num_args() < 3) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5558', + 'Not passing $type to Statement::bindParam() is deprecated.' + . ' Pass the type corresponding to the parameter being bound.' + ); + } + $this->params[$param] = $variable; $this->types[$param] = $type;