Skip to content

print_r() results in warning: unexpected NAN value was coerced to string #23662

Description

@ausi

Description

The following code:

<?php
print_r([NAN]);

Resulted in this output:

Warning: unexpected NAN value was coerced to string in /in/IW2fE on line 3
Array
(
    [0] => NAN
)

But I expected this output instead:

Array
(
    [0] => NAN
)

This warning got introduced in #19573 but I don’t think affecting print_r() was intended as this function is supposed to “Print human-readable information about a variable”.
The related functions var_dump() and var_export() are not affected by this warning.

PHP Version

PHP 8.5.8 (cli) (built: Jul  1 2026 03:46:27) (NTS)
Copyright (c) The PHP Group
Built by Homebrew
Zend Engine v4.5.8, Copyright (c) Zend Technologies
    with Zend OPcache v8.5.8, Copyright (c), by Zend Technologies

Operating System

MacOS 26.6.2

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