Skip to content

PHP 8.5: Warning "unexpected NAN value was coerced to string" when binding NAN to a parameter with PDO #20666

Description

@aaa2000

Description

The following code with PHP 8.5:

<?php$pdo = newPDO("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. 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

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions