mmucklo/inflect
inflect - a memoizing inflector for php
Maintainers
Requires
- php: >=8.1
Requires (Dev)
- phpunit/phpunit: ^10.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
MIT a5bba462e1e686847013dc7c3859f9f3e2ad9c34
- Matthew J. Mucklo <mmucklo.woop@gmail.com>
- Sho Kuwamoto <sho.woop@kuwamoto.org>
This package is auto-updated.
Last update: 2026-06-18 06:56:18 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.3branch 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.phpmoved tosrc/Inflect.php(PSR-0 → PSR-4).Inflectisfinal; rule tables areprivate.pluralize(null)/singularize(null)now throwTypeError.phpunit.xml-distrenamed tophpunit.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.
