Skip to content

[13.x] Fix incorrect @return types in Number::spell(), ordinal(), and spellOrdinal()#60263

Merged
taylorotwell merged 3 commits into
laravel:13.xfrom
AmdadulShakib:fix/number-docblock-return-types
May 25, 2026
Merged

[13.x] Fix incorrect @return types in Number::spell(), ordinal(), and spellOrdinal()#60263
taylorotwell merged 3 commits into
laravel:13.xfrom
AmdadulShakib:fix/number-docblock-return-types

Conversation

@AmdadulShakib
Copy link
Copy Markdown
Contributor

Changes

Fix incorrect @return type annotations on three methods in the Number class.

According to the PHP documentation,
NumberFormatter::format() returns string|false — it returns false on failure.

The following methods call NumberFormatter::format() internally but their
docblocks incorrectly promised only string:

  • Number::spell() — when $number <= $after or $number >= $until, it falls
    through to static::format() which can return false
  • Number::ordinal() — calls $formatter->format($number) directly
  • Number::spellOrdinal() — calls $formatter->format($number) directly

This causes incorrect static analysis results (PHPStan/Psalm) when these return
values are used as strings without null/false checks.

@taylorotwell taylorotwell merged commit 7104220 into laravel:13.x May 25, 2026
54 checks passed
@shaedrich
Copy link
Copy Markdown
Contributor

I wonder whether we want to return false or actually do something else when the underlying NumberFormatter returns false

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.

3 participants