Skip to content

Fix GH-23662: avoid NAN warning in print_r() - #23668

Open
CodedByManish wants to merge 1 commit into
php:masterfrom
CodedByManish:fix/gh-23662-print-r-nan
Open

Fix GH-23662: avoid NAN warning in print_r()#23668
CodedByManish wants to merge 1 commit into
php:masterfrom
CodedByManish:fix/gh-23662-print-r-nan

Conversation

@CodedByManish

Copy link
Copy Markdown

Fixes #23662.

print_r() currently converts double values through string coercion, which causes a warning when the value is NAN.

Handle IS_DOUBLE directly in zend_print_zval_r_to_buf() using smart_str_append_double(), so print_r() formats the value without triggering a coercion warning.

Added a regression test covering print_r([NAN]).

Tested with:
./sapi/cli/php -n run-tests.php Zend/tests/gh23662.phpt

Result: PASS.

@ausi

ausi commented Sep 12, 2026

Copy link
Copy Markdown

Should we add the case for print_r(NAN); (without an array) as well?
But I’m not sure if the warning should appear in this case or not.

@CodedByManish

Copy link
Copy Markdown
Author

Should we add the case for print_r(NAN); (without an array) as well? But I’m not sure if the warning should appear in this case or not.

I checked the scalar case as well. print_r(NAN) doesn’t reproduce the warning, while print_r([NAN]) does. So I’ve kept the test focused on the reported case.

@ausi

ausi commented Sep 12, 2026

Copy link
Copy Markdown

print_r(NAN) doesn’t reproduce the warning, while print_r([NAN]) does.

In my test, print_r(NAN) also shows the warning, see https://3v4l.org/LjTUS#veol

@CodedByManish
CodedByManish force-pushed the fix/gh-23662-print-r-nan branch from 0c102c4 to 3b9d35a Compare September 13, 2026 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants