diff --git a/UPGRADE.md b/UPGRADE.md index a757d169ce6..3f8966f46bc 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -8,6 +8,10 @@ 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 using NULL as prepared statement parameter type. The value of parameter type used in the wrapper layer (e.g. in `Connection::executeQuery()` diff --git a/src/Driver/IBMDB2/Statement.php b/src/Driver/IBMDB2/Statement.php index 453a0f2ebb4..9aed4de77ca 100644 --- a/src/Driver/IBMDB2/Statement.php +++ b/src/Driver/IBMDB2/Statement.php @@ -17,7 +17,6 @@ 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 +51,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); diff --git a/src/Driver/Middleware/AbstractStatementMiddleware.php b/src/Driver/Middleware/AbstractStatementMiddleware.php index d566810fa74..e00e45ee9f9 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,35 +14,17 @@ 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); } diff --git a/src/Driver/Mysqli/Statement.php b/src/Driver/Mysqli/Statement.php index 94e5f20f23b..c4d87dfff48 100644 --- a/src/Driver/Mysqli/Statement.php +++ b/src/Driver/Mysqli/Statement.php @@ -19,7 +19,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,37 +55,19 @@ 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]; diff --git a/src/Driver/OCI8/Statement.php b/src/Driver/OCI8/Statement.php index 486486fb9ce..c452e37eefa 100644 --- a/src/Driver/OCI8/Statement.php +++ b/src/Driver/OCI8/Statement.php @@ -10,7 +10,6 @@ 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 +40,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); 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..9b6a5ab401a 100644 --- a/src/Driver/PDO/Statement.php +++ b/src/Driver/PDO/Statement.php @@ -12,8 +12,6 @@ use PDOException; use PDOStatement; -use function func_num_args; - final class Statement implements StatementInterface { /** @@ -23,17 +21,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 +35,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)); diff --git a/src/Driver/SQLSrv/Statement.php b/src/Driver/SQLSrv/Statement.php index b42f9d13ffd..61617fa50c1 100644 --- a/src/Driver/SQLSrv/Statement.php +++ b/src/Driver/SQLSrv/Statement.php @@ -11,7 +11,6 @@ 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 +67,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 +78,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; diff --git a/src/Driver/Statement.php b/src/Driver/Statement.php index 9ded2932196..f37a78bd581 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,7 +58,7 @@ 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; diff --git a/src/Logging/Statement.php b/src/Logging/Statement.php index 891c2d4951e..d789bae7c5d 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,35 +32,17 @@ 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; diff --git a/tests/Logging/MiddlewareTest.php b/tests/Logging/MiddlewareTest.php index c23fd195641..d3df2444fb6 100644 --- a/tests/Logging/MiddlewareTest.php +++ b/tests/Logging/MiddlewareTest.php @@ -140,7 +140,7 @@ public function testExecuteStatementWithNamedParameters(): void $connection = $this->driver->connect([]); $statement = $connection->prepare('SELECT :value'); - $statement->bindValue('value', 'Test'); + $statement->bindValue('value', 'Test', ParameterType::STRING); $statement->execute(); }