Skip to content

number_format function gives an out of memory error for bad $decimals value #17384

@phpfui

Description

@phpfui

Description

The following code:

number_format(1.23456, 9876543210);

Resulted in this output:

Fatal error: Allowed memory size of 1342177280 bytes exhausted (tried to allocate 2147483680 bytes)

But I expected this output instead:

Anything but a out of memory error.

This is obviously not a high priority issue, as the $decimal parameter is invalid, but thought I would report it.

It produces the output of "1" in PHP versions 8.0.30 and 7.4.33. I would consider this an acceptable value. Or maybe 1.23456, or an error message, thrown exception, but not memory exhaustion.

This is easily solved by validation the $decimal parameter, so not high priority.

PHP Version

8.4.0, 8.3.14, 8.2.26, 8.1.31

Operating System

Windows

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions