mmucklo/inflect

inflect - a memoizing inflector for php

Maintainers

Package info

github.com/mmucklo/inflect

pkg:composer/mmucklo/inflect

Statistics

Installs: 23 352 062

Dependents: 19

Suggesters: 0

Stars: 40

Open Issues: 1

v2.0.0 2026-04-13 04:54 UTC

README

CI codecov Scrutinizer Code Quality Latest Stable Version License

Inflect is a memoizing inflector for PHP — pluralize, singularize, and format counted nouns for English.

Requirements

  • PHP 8.1+ (the legacy PHP 5.3 baseline is maintained on the php5.3 branch for back-ports)

Installation

composer require mmucklo/inflect

Usage

use Inflect\Inflect;

Inflect::pluralize('test');        // 'tests'
Inflect::singularize('tests');     // 'test'
Inflect::pluralizeIf(1, 'cat');    // '1 cat'
Inflect::pluralizeIf(3, 'person'); // '3 people'

Irregulars, uncountables, and case are handled automatically:

Inflect::pluralize('Man');         // 'Men'
Inflect::pluralize('datum');       // 'data'
Inflect::pluralize('news');        // 'news'
Inflect::singularize('criteria');  // 'criterion'
Inflect::singularize('Children');  // 'Child'

// Double-inflection is a no-op:
Inflect::pluralize('people');      // 'people'
Inflect::singularize('datum');     // 'datum'

Results are memoized in a process-local static cache.

API

Inflect::pluralize(string $string): string

Returns the plural form of the given word. Empty input returns ''.

Inflect::singularize(string $string): string

Returns the singular form of the given word. Empty input returns ''.

Inflect::pluralizeIf(int $count, string $string): string

Returns "$count $word" with the word pluralized when $count !== 1.

Passing null to any of these methods raises a TypeError — callers should handle null explicitly.

Versioning

Semantic versioning. The currently supported line is 2.x (PHP 8.1+).

See CHANGELOG.md for release history and ROADMAP.md for planned work (locale support, extension APIs, etc.).

Upgrading from 1.x

2.0.0 is a breaking release. Highlights:

  • PHP 8.1+ required (was 5.3.17+).
  • src/Inflect/Inflect.php moved to src/Inflect.php (PSR-0 → PSR-4).
  • Inflect is final; rule tables are private.
  • pluralize(null) / singularize(null) now throw TypeError.
  • phpunit.xml-dist renamed to phpunit.xml.dist (PHPUnit 10 convention).

Full list in the v2.0.0 release notes.

Contributing

See CONTRIBUTING.md for dev setup, running the test / static analysis / style suite, and PR conventions.

Credits

Originally forked from Sho Kuwamoto's improved pluralizer. Many thanks to Sho, and to the Ruby on Rails and Doctrine inflector projects from which rule patterns continue to be borrowed.

License

MIT — see LICENSE.