Skip to content

Conversation

@aaa2000
Copy link

@aaa2000 aaa2000 commented Dec 7, 2025

Q A
Type feature?

When binding a NAN value to a prepared statement parameter, PHP 8.5 emits a warning: "unexpected NAN value was coerced to string". This warning is not present in PHP 8.4, where the value was silently converted to the string "NAN" and handled correctly by PostgreSQL.

The Pull Request contains only a test demonstrating the issue in order to confirm it in the CI

@greg0ire
Copy link
Member

greg0ire commented Dec 7, 2025

When binding a NAN value to a prepared statement parameter, PHP 8.5 emits a warning: "unexpected NAN value was coerced to string".

As it should, right?

This warning is not present in PHP 8.4

Which is a shame right?

the value was silently converted to the string "NAN" and handled correctly by PostgreSQL.

Do you mean that's a desirable behavior?

@aaa2000
Copy link
Author

aaa2000 commented Dec 7, 2025

The silent conversion in PHP 8.4 was useful because:

  • PostgreSQL accepts "NAN" as a valid string representation and handles it as expected.
  • Applications did not need to add special cases for NAN values.
  • No warning was emitted, so no noise in logs or CI.

The warning in PHP 8.5 is technically correct (since NAN is not a string), but it breaks existing applications that relied on the previous behavior.

This behavior was discovered after adding PHP 8.5 to the CI of project api-platform/core api-platform/core#7585.

A Behat test started failing due to the warning:

@!mysql
Scenario Outline: Posting an XML resource with a float value
  When I send a "POST" request to "/resource_with_floats" with body:
  """
  <?xml version="1.0" encoding="UTF-8"?>
  <ResourceWithFloat>
    <myFloatField><value></myFloatField>
  </ResourceWithFloat>
  """
  Then the response status code should be 201
  And the response should be in XML
  And the header "Content-Type" should be equal to "application/xml; charset=utf-8"
  Examples:
    | value |
    | 3.14  |
    | NaN   |
    | INF   |
    | -INF  |

Interestingly, the warning only appears for NaN. INF and -INF do not trigger the same warning in PHP 8.5.
If there is a problem to fix, it might be at the PDO bindValue level, since that’s where the warning is emitted when binding the parameter...

@greg0ire
Copy link
Member

greg0ire commented Dec 7, 2025

If there is a problem to fix, it might be at the PDO bindValue level, since that’s where the warning is emitted when binding the parameter...

Yes… I feel the fix is going to be either there, or the application itself should decide whether to do the conversion (whether it makes sense for it to store NaN or to reject it.

@aaa2000
Copy link
Author

aaa2000 commented Dec 7, 2025

Okay, thanks for the answers.

@aaa2000 aaa2000 closed this Dec 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants