[php-src] Issue #20666: PHP 8.5: Warning "unexpected NAN value was coerced to string" when binding NAN to a parameter with PDO
[email protected] (aaa2000)
| Newsgroups | php.bugs |
|---|---|
| Message-ID | <[email protected]> |
Issue: https://github.com/php/php-src/issues/20666
Author: aaa2000
### Description
The following code with PHP 8.5:
```php
<?php
$pdo = new PDO("sqlite::memory:");
$stmt = $pdo->prepare("
WITH dummy(value) AS (VALUES ('1'), ('2'))
SELECT * FROM dummy WHERE value = :value
");
$stmt->bindValue(":value", NAN, PDO::PARAM_STR);
$stmt->execute();
var_dump($stmt->fetchAll())
```
Resulted in this output:
```
Warning: unexpected NAN value was coerced to string...
array(0) {
}
```
But I "expected" this output instead:
```
array(0) {
}
```
When binding a NAN value to a PDO statement using PDO::PARAM_STR in PHP 8.5, a warning is emitted:
```
Warning: unexpected NAN value was coerced to string
```
This warning does not occur in PHP 8.4, and the behavior is consistent with the [PHP 8.5 Warnings RFC](https://wiki.php.net/rfc/warnings-php-8-5#coercing_nan_to_other_types). So this might not be a bug, in that case, sorry for the inconvenience.
If I want to keep the current logic and suppress the warning, I think I have to do:
```
$stmt->bindValue(':value', is_nan($value) ? 'NAN' : $value, PDO::PARAM_STR);
```
but in my case I depend on the doctrine ORM...
Notes:
- PostgreSQL accepts "NAN" as a valid string representation not SQLite (that I used in the reproduction code)
- INF and -INF do not trigger this warning
### PHP Version
```plain
PHP 8.5.0 (cli) (built: Nov 20 2025 19:48:03) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.5.0, Copyright (c) Zend Technologies
with Zend OPcache v8.5.0, Copyright (c), by Zend Technologies
```
### Operating System
_No response_