print_r() results in warning: unexpected NAN value was coerced to string
Author: ausiCreated Sep 11, 2026Updated Sep 14, 2026
LabelsBugExtension: standardStatus: Verified
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 https://github.com/php/php-src/pull/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 TechnologiesOperating System
MacOS 26.6.2
Source: php/php-src