diff --git a/UPGRADE.md b/UPGRADE.md
index d9111306612..1bf5c94c447 100644
--- a/UPGRADE.md
+++ b/UPGRADE.md
@@ -8,6 +8,15 @@ awareness about deprecated code.
# Upgrade to 4.0
+## BC BREAK: made parameter type in driver-level `Statement::bind*()` methods required.
+
+The `$type` parameter of the driver-level `Statement::bindParam()` and `::bindValue()` has been made required.
+
+## BC BREAK: removed support for using NULL as prepared statement parameter type.
+
+The value of parameter type used in the wrapper layer (e.g. in `Connection::executeQuery()`
+or `Statement::bindValue()`) can no longer be `NULL`.
+
## BC BREAK: converted enum-like classes to enums
The following classes have been converted to enums:
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index 951ab36a0e3..4acb7c33cfa 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -124,9 +124,4 @@
src/ParameterType.php
-
-
-
- src/Cache/QueryCacheProfile.php
-
diff --git a/src/Cache/QueryCacheProfile.php b/src/Cache/QueryCacheProfile.php
index 4633dc01396..619d5e44aa5 100644
--- a/src/Cache/QueryCacheProfile.php
+++ b/src/Cache/QueryCacheProfile.php
@@ -52,9 +52,9 @@ public function getCacheKey(): string
/**
* Generates the real cache key from query, params, types and connection parameters.
*
- * @param list|array $params
- * @param array|array $types
- * @param array $connectionParams
+ * @param list|array $params
+ * @param array|array $types
+ * @param array $connectionParams
*
* @return string[]
*/
diff --git a/src/Connection.php b/src/Connection.php
index 7ca488b6d61..42e375d87f5 100644
--- a/src/Connection.php
+++ b/src/Connection.php
@@ -361,8 +361,8 @@ public function setAutoCommit(bool $autoCommit): void
* Prepares and executes an SQL query and returns the first row of the result
* as an associative array.
*
- * @param list|array $params
- * @param array|array $types
+ * @param list|array $params
+ * @param array|array $types
*
* @return array|false False is returned if no rows are found.
*
@@ -377,8 +377,8 @@ public function fetchAssociative(string $query, array $params = [], array $types
* Prepares and executes an SQL query and returns the first row of the result
* as a numerically indexed array.
*
- * @param list|array $params
- * @param array|array $types
+ * @param list|array $params
+ * @param array|array $types
*
* @return list|false False is returned if no rows are found.
*
@@ -393,8 +393,8 @@ public function fetchNumeric(string $query, array $params = [], array $types = [
* Prepares and executes an SQL query and returns the value of a single column
* of the first row of the result.
*
- * @param list|array $params
- * @param array|array $types
+ * @param list|array $params
+ * @param array|array $types
*
* @return mixed|false False is returned if no rows are found.
*
@@ -456,8 +456,8 @@ private function addCriteriaCondition(
*
* Table expression and columns are not escaped and are not safe for user-input.
*
- * @param array $criteria
- * @param array|array $types
+ * @param array $criteria
+ * @param array|array $types
*
* @return int|string The number of affected rows.
*
@@ -520,9 +520,9 @@ public function getTransactionIsolation(): TransactionIsolationLevel
*
* Table expression and columns are not escaped and are not safe for user-input.
*
- * @param array $data
- * @param array $criteria
- * @param array|array $types
+ * @param array $data
+ * @param array $criteria
+ * @param array|array $types
*
* @return int|string The number of affected rows.
*
@@ -555,8 +555,8 @@ public function update(string $table, array $data, array $criteria, array $types
*
* Table expression and columns are not escaped and are not safe for user-input.
*
- * @param array $data
- * @param array|array $types
+ * @param array $data
+ * @param array|array $types
*
* @return int|string The number of affected rows.
*
@@ -589,10 +589,10 @@ public function insert(string $table, array $data, array $types = []): int|strin
/**
* Extract ordered type list from an ordered column list and type map.
*
- * @param array $columns
- * @param array|array $types
+ * @param array $columns
+ * @param array|array $types
*
- * @return array|array
+ * @return array|array
*/
private function extractTypeValues(array $columns, array $types): array
{
@@ -636,8 +636,8 @@ public function quote(string $value): string
/**
* Prepares and executes an SQL query and returns the result as an array of numeric arrays.
*
- * @param list|array $params
- * @param array|array $types
+ * @param list|array $params
+ * @param array|array $types
*
* @return list>
*
@@ -651,8 +651,8 @@ public function fetchAllNumeric(string $query, array $params = [], array $types
/**
* Prepares and executes an SQL query and returns the result as an array of associative arrays.
*
- * @param list|array $params
- * @param array|array $types
+ * @param list|array $params
+ * @param array|array $types
*
* @return list>
*
@@ -667,8 +667,8 @@ public function fetchAllAssociative(string $query, array $params = [], array $ty
* Prepares and executes an SQL query and returns the result as an associative array with the keys
* mapped to the first column and the values mapped to the second column.
*
- * @param list|array $params
- * @param array|array $types
+ * @param list|array $params
+ * @param array|array $types
*
* @return array
*
@@ -684,8 +684,8 @@ public function fetchAllKeyValue(string $query, array $params = [], array $types
* to the first column and the values being an associative array representing the rest of the columns
* and their values.
*
- * @param list|array $params
- * @param array|array $types
+ * @param list|array $params
+ * @param array|array $types
*
* @return array>
*
@@ -699,8 +699,8 @@ public function fetchAllAssociativeIndexed(string $query, array $params = [], ar
/**
* Prepares and executes an SQL query and returns the result as an array of the first column values.
*
- * @param list|array $params
- * @param array|array $types
+ * @param list|array $params
+ * @param array|array $types
*
* @return list
*
@@ -714,8 +714,8 @@ public function fetchFirstColumn(string $query, array $params = [], array $types
/**
* Prepares and executes an SQL query and returns the result as an iterator over rows represented as numeric arrays.
*
- * @param list|array $params
- * @param array|array $types
+ * @param list|array $params
+ * @param array|array $types
*
* @return Traversable>
*
@@ -730,8 +730,8 @@ public function iterateNumeric(string $query, array $params = [], array $types =
* Prepares and executes an SQL query and returns the result as an iterator over rows represented
* as associative arrays.
*
- * @param list|array $params
- * @param array|array $types
+ * @param list|array $params
+ * @param array|array $types
*
* @return Traversable>
*
@@ -746,8 +746,8 @@ public function iterateAssociative(string $query, array $params = [], array $typ
* Prepares and executes an SQL query and returns the result as an iterator with the keys
* mapped to the first column and the values mapped to the second column.
*
- * @param list|array $params
- * @param array|array $types
+ * @param list|array $params
+ * @param array|array $types
*
* @return Traversable
*
@@ -779,8 +779,8 @@ public function iterateAssociativeIndexed(string $query, array $params = [], arr
/**
* Prepares and executes an SQL query and returns the result as an iterator over the first column values.
*
- * @param list|array $params
- * @param array|array $types
+ * @param list|array $params
+ * @param array|array $types
*
* @return Traversable
*
@@ -816,8 +816,8 @@ public function prepare(string $sql): Statement
*
* If the query is parametrized, a prepared statement is used.
*
- * @param list|array $params
- * @param array|array $types
+ * @param list|array $params
+ * @param array|array $types
*
* @throws Exception
*/
@@ -855,8 +855,8 @@ public function executeQuery(
/**
* Executes a caching query.
*
- * @param list|array $params
- * @param array|array $types
+ * @param list|array $params
+ * @param array|array $types
*
* @throws CacheException
* @throws Exception
@@ -913,8 +913,8 @@ public function executeCacheQuery(string $sql, array $params, array $types, Quer
*
* This method supports PDO binding types as well as DBAL mapping types.
*
- * @param list|array $params
- * @param array|array $types
+ * @param list|array $params
+ * @param array|array $types
*
* @throws Exception
*/
@@ -1302,8 +1302,8 @@ public function convertToPHPValue(mixed $value, string $type): mixed
* Binds a set of parameters, some or all of which are typed with a PDO binding type
* or DBAL mapping type, to a given statement.
*
- * @param list|array $params
- * @param array|array $types
+ * @param list|array $params
+ * @param array|array $types
*
* @throws Exception
*/
@@ -1314,19 +1314,10 @@ private function bindParameters(DriverStatement $stmt, array $params, array $typ
$bindIndex = 1;
foreach ($params as $key => $value) {
- if (isset($types[$key])) {
+ if (array_key_exists($key, $types)) {
$type = $types[$key];
[$value, $bindingType] = $this->getBindingInfo($value, $type);
} else {
- if (array_key_exists($key, $types)) {
- Deprecation::trigger(
- 'doctrine/dbal',
- 'https://github.com/doctrine/dbal/pull/5550',
- 'Using NULL as prepared statement parameter type is deprecated.'
- . 'Omit or use Parameter::STRING instead'
- );
- }
-
$bindingType = ParameterType::STRING;
}
@@ -1337,19 +1328,10 @@ private function bindParameters(DriverStatement $stmt, array $params, array $typ
} else {
// Named parameters
foreach ($params as $name => $value) {
- if (isset($types[$name])) {
+ if (array_key_exists($name, $types)) {
$type = $types[$name];
[$value, $bindingType] = $this->getBindingInfo($value, $type);
} else {
- if (array_key_exists($name, $types)) {
- Deprecation::trigger(
- 'doctrine/dbal',
- 'https://github.com/doctrine/dbal/pull/5550',
- 'Using NULL as prepared statement parameter type is deprecated.'
- . 'Omit or use Parameter::STRING instead'
- );
- }
-
$bindingType = ParameterType::STRING;
}
@@ -1361,14 +1343,14 @@ private function bindParameters(DriverStatement $stmt, array $params, array $typ
/**
* Gets the binding type of a given type.
*
- * @param mixed $value The value to bind.
- * @param string|ParameterType|Type|null $type The type to bind.
+ * @param mixed $value The value to bind.
+ * @param string|ParameterType|Type $type The type to bind.
*
* @return array{mixed, ParameterType} [0] => the (escaped) value, [1] => the binding type.
*
* @throws Exception
*/
- private function getBindingInfo(mixed $value, string|ParameterType|Type|null $type): array
+ private function getBindingInfo(mixed $value, string|ParameterType|Type $type): array
{
if (is_string($type)) {
$type = Type::getType($type);
@@ -1378,7 +1360,7 @@ private function getBindingInfo(mixed $value, string|ParameterType|Type|null $ty
$value = $type->convertToDatabaseValue($value, $this->getDatabasePlatform());
$bindingType = $type->getBindingType();
} else {
- $bindingType = $type ?? ParameterType::STRING;
+ $bindingType = $type;
}
return [$value, $bindingType];
@@ -1395,8 +1377,8 @@ public function createQueryBuilder(): QueryBuilder
/**
* @internal
*
- * @param list|array $params
- * @param array|array $types
+ * @param list|array $params
+ * @param array|array $types
*/
final public function convertExceptionDuringQuery(
Driver\Exception $e,
@@ -1416,13 +1398,13 @@ final public function convertException(Driver\Exception $e): DriverException
}
/**
- * @param array|array $params
- * @param array|array $types
+ * @param array|array $params
+ * @param array|array $types
*
* @return array{
* string,
* array|array,
- * array|array
+ * array|array
* }
*/
private function expandArrayParameters(string $sql, array $params, array $types): array
@@ -1478,8 +1460,8 @@ private function handleDriverException(
*
* @deprecated This API is deprecated and will be removed after 2022
*
- * @param array|array $params
- * @param array|array $types
+ * @param array|array $params
+ * @param array|array $types
*
* @throws Exception
*/
diff --git a/src/Driver/IBMDB2/Statement.php b/src/Driver/IBMDB2/Statement.php
index 453a0f2ebb4..62191c29b0a 100644
--- a/src/Driver/IBMDB2/Statement.php
+++ b/src/Driver/IBMDB2/Statement.php
@@ -10,14 +10,12 @@
use Doctrine\DBAL\Driver\IBMDB2\Exception\StatementError;
use Doctrine\DBAL\Driver\Statement as StatementInterface;
use Doctrine\DBAL\ParameterType;
-use Doctrine\Deprecations\Deprecation;
use function assert;
use function db2_bind_param;
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;
@@ -52,39 +50,17 @@ public function __construct(private readonly mixed $stmt)
{
}
- public function bindValue(int|string $param, mixed $value, ParameterType $type = ParameterType::STRING): void
+ public function bindValue(int|string $param, mixed $value, ParameterType $type): void
{
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->bindParam($param, $value, $type);
}
- public function bindParam(
- int|string $param,
- mixed &$variable,
- ParameterType $type = ParameterType::STRING,
- ?int $length = null
- ): void {
+ public function bindParam(int|string $param, mixed &$variable, ParameterType $type, ?int $length = null): void
+ {
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);
@@ -112,20 +88,11 @@ private function bind(int $position, mixed &$variable, int $parameterType, int $
}
}
- public function execute(?array $params = null): Result
+ public function execute(): Result
{
- if ($params !== null) {
- Deprecation::trigger(
- 'doctrine/dbal',
- 'https://github.com/doctrine/dbal/pull/5556',
- 'Passing $params to Statement::execute() is deprecated. Bind parameters using'
- . ' Statement::bindParam() or Statement::bindValue() instead.'
- );
- }
-
$handles = $this->bindLobs();
- $result = @db2_execute($this->stmt, $params ?? $this->parameters);
+ $result = @db2_execute($this->stmt, $this->parameters);
foreach ($handles as $handle) {
fclose($handle);
diff --git a/src/Driver/Middleware/AbstractStatementMiddleware.php b/src/Driver/Middleware/AbstractStatementMiddleware.php
index d566810fa74..91c995db44a 100644
--- a/src/Driver/Middleware/AbstractStatementMiddleware.php
+++ b/src/Driver/Middleware/AbstractStatementMiddleware.php
@@ -7,9 +7,6 @@
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
{
@@ -17,40 +14,22 @@ public function __construct(private readonly Statement $wrappedStatement)
{
}
- public function bindValue(int|string $param, mixed $value, ParameterType $type = ParameterType::STRING): void
+ public function bindValue(int|string $param, mixed $value, ParameterType $type): void
{
- 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->wrappedStatement->bindValue($param, $value, $type);
}
public function bindParam(
int|string $param,
mixed &$variable,
- ParameterType $type = ParameterType::STRING,
+ ParameterType $type,
?int $length = null
): void {
- 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->wrappedStatement->bindParam($param, $variable, $type, $length);
}
- public function execute(?array $params = null): Result
+ public function execute(): Result
{
- return $this->wrappedStatement->execute($params);
+ return $this->wrappedStatement->execute();
}
}
diff --git a/src/Driver/Mysqli/Statement.php b/src/Driver/Mysqli/Statement.php
index 94e5f20f23b..519f4e065d0 100644
--- a/src/Driver/Mysqli/Statement.php
+++ b/src/Driver/Mysqli/Statement.php
@@ -10,7 +10,6 @@
use Doctrine\DBAL\Driver\Mysqli\Exception\StatementError;
use Doctrine\DBAL\Driver\Statement as StatementInterface;
use Doctrine\DBAL\ParameterType;
-use Doctrine\Deprecations\Deprecation;
use mysqli_sql_exception;
use mysqli_stmt;
@@ -19,7 +18,6 @@
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;
@@ -56,57 +54,28 @@ public function __construct(private readonly mysqli_stmt $stmt)
public function bindParam(
int|string $param,
mixed &$variable,
- ParameterType $type = ParameterType::STRING,
+ ParameterType $type,
?int $length = null
): void {
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->types[$param - 1] = $this->convertParameterType($type);
$this->boundValues[$param] =& $variable;
}
- public function bindValue(int|string $param, mixed $value, ParameterType $type = ParameterType::STRING): void
+ public function bindValue(int|string $param, mixed $value, ParameterType $type): void
{
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->types[$param - 1] = $this->convertParameterType($type);
$this->values[$param] = $value;
$this->boundValues[$param] =& $this->values[$param];
}
- public function execute(?array $params = null): Result
+ public function execute(): Result
{
- if ($params !== null) {
- Deprecation::trigger(
- 'doctrine/dbal',
- 'https://github.com/doctrine/dbal/pull/5556',
- 'Passing $params to Statement::execute() is deprecated. Bind parameters using'
- . ' Statement::bindParam() or Statement::bindValue() instead.'
- );
- }
-
- if ($params !== null && count($params) > 0) {
- $this->bindUntypedValues($params);
- } elseif (count($this->boundValues) > 0) {
- $this->bindTypedParameters();
+ if (count($this->boundValues) > 0) {
+ $this->bindParameters();
}
try {
@@ -125,7 +94,7 @@ public function execute(?array $params = null): Result
*
* @throws Exception
*/
- private function bindTypedParameters(): void
+ private function bindParameters(): void
{
$streams = $values = [];
$types = $this->types;
@@ -184,20 +153,6 @@ private function sendLongData(array $streams): void
}
}
- /**
- * Binds a array of values to bound parameters.
- *
- * @param mixed[] $values
- *
- * @throws Exception
- */
- private function bindUntypedValues(array $values): void
- {
- if (! $this->stmt->bind_param(str_repeat(self::PARAMETER_TYPE_STRING, count($values)), ...$values)) {
- throw StatementError::new($this->stmt);
- }
- }
-
private function convertParameterType(ParameterType $type): string
{
return match ($type) {
diff --git a/src/Driver/OCI8/Statement.php b/src/Driver/OCI8/Statement.php
index 486486fb9ce..55c2e89e6d2 100644
--- a/src/Driver/OCI8/Statement.php
+++ b/src/Driver/OCI8/Statement.php
@@ -8,9 +8,7 @@
use Doctrine\DBAL\Driver\OCI8\Exception\UnknownParameterIndex;
use Doctrine\DBAL\Driver\Statement as StatementInterface;
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;
@@ -41,35 +39,17 @@ public function __construct(
) {
}
- public function bindValue(int|string $param, mixed $value, ParameterType $type = ParameterType::STRING): void
+ public function bindValue(int|string $param, mixed $value, ParameterType $type): void
{
- 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->bindParam($param, $value, $type);
}
public function bindParam(
int|string $param,
mixed &$variable,
- ParameterType $type = ParameterType::STRING,
+ ParameterType $type,
?int $length = null
): void {
- 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);
@@ -114,27 +94,8 @@ private function convertParameterType(ParameterType $type): int
};
}
- public function execute(?array $params = null): Result
+ public function execute(): Result
{
- if ($params !== null) {
- Deprecation::trigger(
- 'doctrine/dbal',
- 'https://github.com/doctrine/dbal/pull/5556',
- 'Passing $params to Statement::execute() is deprecated. Bind parameters using'
- . ' Statement::bindParam() or Statement::bindValue() instead.'
- );
-
- foreach ($params as $key => $val) {
- if (is_int($key)) {
- $param = $key + 1;
- } else {
- $param = $key;
- }
-
- $this->bindValue($param, $val, ParameterType::STRING);
- }
- }
-
if ($this->executionMode->isAutoCommitEnabled()) {
$mode = OCI_COMMIT_ON_SUCCESS;
} else {
diff --git a/src/Driver/PDO/SQLSrv/Statement.php b/src/Driver/PDO/SQLSrv/Statement.php
index 7d9694bbe02..955eccd5204 100644
--- a/src/Driver/PDO/SQLSrv/Statement.php
+++ b/src/Driver/PDO/SQLSrv/Statement.php
@@ -7,11 +7,8 @@
use Doctrine\DBAL\Driver\Middleware\AbstractStatementMiddleware;
use Doctrine\DBAL\Driver\PDO\Statement as PDOStatement;
use Doctrine\DBAL\ParameterType;
-use Doctrine\Deprecations\Deprecation;
use PDO;
-use function func_num_args;
-
final class Statement extends AbstractStatementMiddleware
{
private readonly PDOStatement $statement;
@@ -29,18 +26,9 @@ public function __construct(PDOStatement $statement)
public function bindParam(
int|string $param,
mixed &$variable,
- ParameterType $type = ParameterType::STRING,
+ ParameterType $type,
?int $length = null
): void {
- 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::LARGE_OBJECT:
case ParameterType::BINARY:
@@ -68,17 +56,8 @@ public function bindParam(
}
}
- public function bindValue(int|string $param, mixed $value, ParameterType $type = ParameterType::STRING): void
+ public function bindValue(int|string $param, mixed $value, ParameterType $type): void
{
- 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->bindParam($param, $value, $type);
}
}
diff --git a/src/Driver/PDO/Statement.php b/src/Driver/PDO/Statement.php
index 35b6c3afa72..35dcf055a32 100644
--- a/src/Driver/PDO/Statement.php
+++ b/src/Driver/PDO/Statement.php
@@ -7,13 +7,10 @@
use Doctrine\DBAL\Driver\Exception as ExceptionInterface;
use Doctrine\DBAL\Driver\Statement as StatementInterface;
use Doctrine\DBAL\ParameterType;
-use Doctrine\Deprecations\Deprecation;
use PDO;
use PDOException;
use PDOStatement;
-use function func_num_args;
-
final class Statement implements StatementInterface
{
/**
@@ -23,17 +20,8 @@ public function __construct(private readonly PDOStatement $stmt)
{
}
- public function bindValue(int|string $param, mixed $value, ParameterType $type = ParameterType::STRING): void
+ public function bindValue(int|string $param, mixed $value, ParameterType $type): void
{
- 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 {
@@ -46,18 +34,9 @@ public function bindValue(int|string $param, mixed $value, ParameterType $type =
public function bindParam(
string|int $param,
mixed &$variable,
- ParameterType $type = ParameterType::STRING,
+ ParameterType $type,
?int $length = null
): void {
- 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.'
- );
- }
-
try {
if ($length === null) {
$this->stmt->bindParam($param, $variable, $this->convertParamType($type));
@@ -88,19 +67,10 @@ public function bindParamWithDriverOptions(
}
}
- public function execute(?array $params = null): Result
+ public function execute(): Result
{
- if ($params !== null) {
- Deprecation::trigger(
- 'doctrine/dbal',
- 'https://github.com/doctrine/dbal/pull/5556',
- 'Passing $params to Statement::execute() is deprecated. Bind parameters using'
- . ' Statement::bindParam() or Statement::bindValue() instead.'
- );
- }
-
try {
- $this->stmt->execute($params);
+ $this->stmt->execute();
} catch (PDOException $exception) {
throw Exception::new($exception);
}
diff --git a/src/Driver/SQLSrv/Statement.php b/src/Driver/SQLSrv/Statement.php
index b42f9d13ffd..850b6baf9e5 100644
--- a/src/Driver/SQLSrv/Statement.php
+++ b/src/Driver/SQLSrv/Statement.php
@@ -8,10 +8,8 @@
use Doctrine\DBAL\Driver\SQLSrv\Exception\Error;
use Doctrine\DBAL\Driver\Statement as StatementInterface;
use Doctrine\DBAL\ParameterType;
-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;
@@ -68,19 +66,10 @@ public function __construct(
$this->sql .= self::LAST_INSERT_ID_SQL;
}
- public function bindValue(int|string $param, mixed $value, ParameterType $type = ParameterType::STRING): void
+ public function bindValue(int|string $param, mixed $value, ParameterType $type): void
{
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;
}
@@ -88,20 +77,11 @@ public function bindValue(int|string $param, mixed $value, ParameterType $type =
public function bindParam(
int|string $param,
mixed &$variable,
- ParameterType $type = ParameterType::STRING,
+ ParameterType $type,
?int $length = null
): void {
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;
@@ -109,25 +89,8 @@ public function bindParam(
$this->stmt = null;
}
- public function execute(?array $params = null): Result
+ public function execute(): Result
{
- if ($params !== null) {
- Deprecation::trigger(
- 'doctrine/dbal',
- 'https://github.com/doctrine/dbal/pull/5556',
- 'Passing $params to Statement::execute() is deprecated. Bind parameters using'
- . ' Statement::bindParam() or Statement::bindValue() instead.'
- );
-
- foreach ($params as $key => $val) {
- if (is_int($key)) {
- $this->bindValue($key + 1, $val, ParameterType::STRING);
- } else {
- $this->bindValue($key, $val, ParameterType::STRING);
- }
- }
- }
-
$this->stmt ??= $this->prepare();
if (! sqlsrv_execute($this->stmt)) {
diff --git a/src/Driver/Statement.php b/src/Driver/Statement.php
index 9ded2932196..cf5f8a0e2c7 100644
--- a/src/Driver/Statement.php
+++ b/src/Driver/Statement.php
@@ -28,7 +28,7 @@ interface Statement
*
* @throws Exception
*/
- public function bindValue(int|string $param, mixed $value, ParameterType $type = ParameterType::STRING): void;
+ public function bindValue(int|string $param, mixed $value, ParameterType $type): void;
/**
* Binds a PHP variable to a corresponding named (not supported by mysqli driver, see comment below) or question
@@ -49,7 +49,7 @@ public function bindValue(int|string $param, mixed $value, ParameterType $type =
* question mark placeholders, this will be the 1-indexed position of the parameter.
* @param mixed $variable The variable to bind to the parameter.
* @param ParameterType $type Explicit data type for the parameter using the {@see ParameterType}
- * constants.
+ * constants.
* @param int|null $length You must specify maxlength when using an OUT bind
* so that PHP allocates enough memory to hold the returned value.
*
@@ -58,23 +58,14 @@ public function bindValue(int|string $param, mixed $value, ParameterType $type =
public function bindParam(
int|string $param,
mixed &$variable,
- ParameterType $type = ParameterType::STRING,
+ ParameterType $type,
?int $length = null
): void;
/**
* Executes a prepared statement
*
- * If the prepared statement included parameter markers, you must either:
- * call {@see bindParam()} to bind PHP variables to the parameter markers:
- * bound variables pass their value as input and receive the output value,
- * if any, of their associated parameter markers or pass an array of input-only
- * parameter values.
- *
- * @param mixed[]|null $params A numeric array of values with as many elements as there are
- * bound parameters in the SQL statement being executed.
- *
* @throws Exception
*/
- public function execute(?array $params = null): Result;
+ public function execute(): Result;
}
diff --git a/src/ExpandArrayParameters.php b/src/ExpandArrayParameters.php
index 0e7e8ad2c50..4daae7bc7df 100644
--- a/src/ExpandArrayParameters.php
+++ b/src/ExpandArrayParameters.php
@@ -27,12 +27,12 @@ final class ExpandArrayParameters implements Visitor
/** @var list */
private array $convertedParameters = [];
- /** @var array */
+ /** @var array */
private array $convertedTypes = [];
/**
- * @param array|array $parameters
- * @param array|array $types
+ * @param array|array $parameters
+ * @param array|array $types
*/
public function __construct(private readonly array $parameters, private readonly array $types)
{
@@ -115,7 +115,7 @@ private function acceptParameter(int|string $key, mixed $value): void
}
/**
- * @return array
+ * @return array
*/
public function getTypes(): array
{
@@ -125,7 +125,7 @@ public function getTypes(): array
/**
* @param list $values
*/
- private function appendTypedParameter(array $values, string|ParameterType|Type|null $type): void
+ private function appendTypedParameter(array $values, string|ParameterType|Type $type): void
{
$this->convertedSQL[] = implode(', ', array_fill(0, count($values), '?'));
diff --git a/src/Logging/Statement.php b/src/Logging/Statement.php
index 891c2d4951e..6a639b838e2 100644
--- a/src/Logging/Statement.php
+++ b/src/Logging/Statement.php
@@ -8,11 +8,8 @@
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 func_num_args;
-
final class Statement extends AbstractStatementMiddleware
{
/** @var array|array */
@@ -35,49 +32,31 @@ public function __construct(
public function bindParam(
int|string $param,
mixed &$variable,
- ParameterType $type = ParameterType::STRING,
+ ParameterType $type,
?int $length = null
): void {
- 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;
parent::bindParam($param, $variable, $type, $length);
}
- public function bindValue(int|string $param, mixed $value, ParameterType $type = ParameterType::STRING): void
+ public function bindValue(int|string $param, mixed $value, ParameterType $type): void
{
- 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;
parent::bindValue($param, $value, $type);
}
- public function execute(?array $params = null): ResultInterface
+ public function execute(): ResultInterface
{
$this->logger->debug('Executing statement: {sql} (parameters: {params}, types: {types})', [
'sql' => $this->sql,
- 'params' => $params ?? $this->params,
+ 'params' => $this->params,
'types' => $this->types,
]);
- return parent::execute($params);
+ return parent::execute();
}
}
diff --git a/src/Portability/Statement.php b/src/Portability/Statement.php
index 659b988c26e..3d005891df4 100644
--- a/src/Portability/Statement.php
+++ b/src/Portability/Statement.php
@@ -21,10 +21,10 @@ public function __construct(DriverStatement $stmt, private readonly Converter $c
parent::__construct($stmt);
}
- public function execute(?array $params = null): ResultInterface
+ public function execute(): ResultInterface
{
return new Result(
- parent::execute($params),
+ parent::execute(),
$this->converter
);
}
diff --git a/src/Query.php b/src/Query.php
index 82e92f3a23b..8caae6ef57b 100644
--- a/src/Query.php
+++ b/src/Query.php
@@ -14,8 +14,8 @@
final class Query
{
/**
- * @param array $params
- * @param array $types
+ * @param array $params
+ * @param array $types
*
* @psalm-suppress ImpurePropertyAssignment
*/
@@ -40,7 +40,7 @@ public function getParams(): array
}
/**
- * @return array
+ * @return array
*/
public function getTypes(): array
{
diff --git a/src/Query/QueryBuilder.php b/src/Query/QueryBuilder.php
index d94a046043c..110b030d0c4 100644
--- a/src/Query/QueryBuilder.php
+++ b/src/Query/QueryBuilder.php
@@ -53,7 +53,7 @@ class QueryBuilder
/**
* The parameter type map of this query.
*
- * @var array|array
+ * @var array|array
*/
private array $types = [];
@@ -353,29 +353,19 @@ public function getSQL(): string
* ->setParameter('user_id', 1);
*
*
- * @param int|string $key Parameter position or name
- * @param mixed $value Parameter value
- * @param string|ParameterType|Type|null $type Parameter type
+ * @param int|string $key Parameter position or name
+ * @param mixed $value Parameter value
+ * @param string|ParameterType|Type $type Parameter type
*
* @return $this This QueryBuilder instance.
*/
public function setParameter(
int|string $key,
mixed $value,
- string|ParameterType|Type|null $type = ParameterType::STRING
+ string|ParameterType|Type $type = ParameterType::STRING
): self {
- if ($type !== null) {
- $this->types[$key] = $type;
- } else {
- Deprecation::trigger(
- 'doctrine/dbal',
- 'https://github.com/doctrine/dbal/pull/5550',
- 'Using NULL as prepared statement parameter type is deprecated.'
- . 'Omit or use Parameter::STRING instead'
- );
- }
-
$this->params[$key] = $value;
+ $this->types[$key] = $type;
return $this;
}
@@ -394,8 +384,8 @@ public function setParameter(
* ));
*
*
- * @param list|array $params
- * @param array|array $types
+ * @param list|array $params
+ * @param array|array $types
*
* @return $this This QueryBuilder instance.
*/
@@ -432,7 +422,7 @@ public function getParameter(string|int $key): mixed
/**
* Gets all defined query parameter types for the query being constructed indexed by parameter index or name.
*
- * @return array|array
+ * @return array|array
*/
public function getParameterTypes(): array
{
@@ -446,7 +436,7 @@ public function getParameterTypes(): array
*
* @return int|string|ParameterType|Type The value of the bound parameter type
*/
- public function getParameterType(int|string $key): int|string|ParameterType|Type|null
+ public function getParameterType(int|string $key): int|string|ParameterType|Type
{
return $this->types[$key] ?? ParameterType::STRING;
}
@@ -1331,7 +1321,7 @@ public function __toString(): string
*/
public function createNamedParameter(
mixed $value,
- string|ParameterType|Type|null $type = ParameterType::STRING,
+ string|ParameterType|Type $type = ParameterType::STRING,
?string $placeHolder = null
): string {
if ($placeHolder === null) {
@@ -1363,7 +1353,7 @@ public function createNamedParameter(
*/
public function createPositionalParameter(
mixed $value,
- string|ParameterType|Type|null $type = ParameterType::STRING
+ string|ParameterType|Type $type = ParameterType::STRING
): string {
$this->setParameter($this->boundCounter, $value, $type);
$this->boundCounter++;
diff --git a/src/Statement.php b/src/Statement.php
index 1f0703ecd49..93b4c96cc6c 100644
--- a/src/Statement.php
+++ b/src/Statement.php
@@ -6,7 +6,6 @@
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
-use Doctrine\Deprecations\Deprecation;
use function func_num_args;
use function is_string;
@@ -135,19 +134,13 @@ public function bindParam(
}
/**
- * @param mixed[] $params
- *
* @throws Exception
*/
- private function execute(array $params): Result
+ private function execute(): Result
{
- if ($params !== []) {
- $this->params = $params;
- }
-
try {
return new Result(
- $this->stmt->execute($params === [] ? null : $params),
+ $this->stmt->execute(),
$this->conn
);
} catch (Driver\Exception $ex) {
@@ -158,43 +151,21 @@ private function execute(array $params): Result
/**
* Executes the statement with the currently bound parameters and return result.
*
- * @param mixed[] $params
- *
* @throws Exception
*/
- public function executeQuery(array $params = []): Result
+ public function executeQuery(): Result
{
- if (func_num_args() > 0) {
- Deprecation::trigger(
- 'doctrine/dbal',
- 'https://github.com/doctrine/dbal/pull/5556',
- 'Passing $params to Statement::executeQuery() is deprecated. Bind parameters using'
- . ' Statement::bindParam() or Statement::bindValue() instead.'
- );
- }
-
- return $this->execute($params);
+ return $this->execute();
}
/**
* Executes the statement with the currently bound parameters and return affected rows.
*
- * @param mixed[] $params
- *
* @throws Exception
*/
- public function executeStatement(array $params = []): int
+ public function executeStatement(): int
{
- if (func_num_args() > 0) {
- Deprecation::trigger(
- 'doctrine/dbal',
- 'https://github.com/doctrine/dbal/pull/5556',
- 'Passing $params to Statement::executeStatement() is deprecated. Bind parameters using'
- . ' Statement::bindParam() or Statement::bindValue() instead.'
- );
- }
-
- return $this->execute($params)->rowCount();
+ return $this->execute()->rowCount();
}
/**
diff --git a/tests/Connection/ExpandArrayParametersTest.php b/tests/Connection/ExpandArrayParametersTest.php
index fb4c63bfb47..f69bf5703fb 100644
--- a/tests/Connection/ExpandArrayParametersTest.php
+++ b/tests/Connection/ExpandArrayParametersTest.php
@@ -318,10 +318,10 @@ public static function dataExpandListParameters(): iterable
}
/**
- * @param array|array $params
- * @param array|array $types
- * @param list $expectedParams
- * @param array $expectedTypes
+ * @param array|array