symfony/polyfill-ctype
Provides a lightweight polyfill for PHP’s ctype_* functions when the ctype extension isn’t available. Part of Symfony’s Polyfill suite, enabling consistent character type checks across environments and older PHP installations.
This package is a lightweight, drop-in polyfill that provides the ctype_* family of functions (e.g., ctype_alnum, ctype_digit, ctype_lower, etc.) for PHP environments where the native ctype extension is not loaded — typically older or stripped-down PHP installations (e.g., some shared hosting or Windows setups without the extension enabled).
First use case: Automatically ensure ctype_* functions exist without conditional checks. Simply install it via Composer (composer require symfony/polyfill-ctype) — no code changes needed. The polyfill auto-registers when the functions are first called, using SPL autoloading.
Where to look first: Check if your target PHP environment has the ctype extension via extension_loaded('ctype'). If unsure (e.g., deploying to multiple environments), include this polyfill to guarantee portability.
ctype_* functions directly in your code — they’ll work out of the box in both ctype-enabled and polyfilled environments.Symfony\Polyfill\Ctype::bootstrap() — though this is usually unnecessary thanks to Composer autoloading.ctype_alnum($slug) for slugs).ctype when available (the polyfill detects the extension and delegates automatically).ctype_* calls in if (!function_exists('ctype_alnum')) — the polyfill always provides the functions, and such checks defeat its purpose.ctype, the polyfill ignores locale and works strictly on ASCII. Don’t use it for multibyte or Unicode text (e.g., ctype_alnum('café') returns false — use mb_ereg_match instead).ctype’s behavior: non-string types are cast to strings (e.g., ctype_digit(42) → true, ctype_digit([1,2]) → false).class_exists(\Symfony\Polyfill\Ctype\Ctype::class) — but again, this is rarely necessary.regex or custom rules) for input that requires stricter constraints.How can I help you explore Laravel packages today?