Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Polyfill Php84

Polyfill Php84 Laravel Package

symfony/polyfill-php84

Symfony Polyfill for PHP 8.4 features on older runtimes. Adds functions like array_find/any/all, bcdivmod, fpow, grapheme_str_split, mb_* trim/ucfirst/lcfirst, Deprecated attribute, cURL HTTP/3 constants, PDO driver subclasses, and ReflectionConstant.

View on GitHub
Deep Wiki
Context7

Symfony polyfill backporting some PHP 8.4+ features to lower PHP versions

Frequently asked questions about Polyfill Php84
How do I use `array_find` or `array_any` in Laravel Collections with this polyfill?
Install the polyfill via Composer (`composer require symfony/polyfill-php84`), then use the new functions directly in Collection callbacks. For example, `collect($items)->filter(fn($item) => array_any($item, fn($val) => $val === 'active'))` works in PHP 7.4+ to mimic PHP 8.4’s functional array methods. No Laravel-specific setup is required beyond the polyfill.
Will this polyfill work with Laravel’s Eloquent or Query Builder?
Yes, the polyfill enhances Eloquent and Query Builder functionality. For instance, you can use `array_find` to dynamically filter `whereIn` clauses: `$query->whereIn('id', array_find($ids, fn($id) => $id > 100))`. It integrates at the PHP runtime level, so no changes to Laravel’s configuration or service container are needed.
Does this polyfill support Laravel’s minimum PHP version (8.0+)?
The polyfill works with PHP 7.2+ (Laravel’s minimum is 8.0), but some features like the `#[Deprecated]` attribute require PHP 8.0+. Test thoroughly in staging, especially for edge cases like `bcdivmod` or PDO subclasses, which may need `ext-bcmath` or `ext-pdo` extensions enabled.
Can I use `bcdivmod` or `bcround` for precise decimal validation in Laravel’s FormRequest?
Absolutely. After installing the polyfill, use `bcround` or `bcdivmod` in custom validation rules within `FormRequest::rules()`, such as `['amount' => 'required|numeric|bc_precision:2']`. This extends Laravel’s Validator without requiring custom logic, ideal for financial or high-precision calculations.
Are there any performance concerns with using polyfilled functions like `array_all` in high-frequency loops?
The polyfill adds negligible overhead (~1MB footprint) and is optimized for compatibility. For most Laravel applications, the performance impact is minimal. However, if you’re processing millions of records in tight loops, benchmark the polyfilled functions against native PHP 8.4 equivalents in your staging environment.
How do I handle multilingual inputs with `grapheme_str_split` or `mb_*` functions in Laravel?
The polyfill’s `grapheme_str_split` and `mb_*` functions (e.g., `mb_trim`, `mb_ucfirst`) simplify handling Unicode strings in Laravel’s `Request` or `FormRequest` validation. For example, use `grapheme_str_split($input, 1)` to process emojis or multibyte characters correctly, reducing the need for custom regex or string manipulation.
Does this polyfill support multi-database setups in Laravel (e.g., MySQL + PostgreSQL)?
Yes, the PDO driver subclasses (e.g., `PDOMySQL`, `PDOPostgreSQL`) allow you to dynamically switch databases in Laravel’s `DB` facade or Eloquent. For example, instantiate a polyfilled driver like `$pdo = new PDOMySQL($dsn)` and use it with Laravel’s query builder. Test thoroughly in staging to ensure compatibility with your database configurations.
Will this polyfill conflict with existing Laravel packages or services?
No, the polyfill operates at the PHP runtime level and doesn’t interact with Laravel’s service container or namespaces. It’s designed to be isolated, so there are no conflicts with packages like `laravel/framework`, `illuminate/collections`, or third-party libraries. Simply require it via Composer and use the new functions globally.
How do I test this polyfill in a Laravel application before production?
Start by installing the polyfill in a staging environment (`composer require symfony/polyfill-php84`). Test critical features like `array_find` in Collections, `bcmath` in validation rules, and PDO subclasses with your database configurations. Use Laravel’s built-in testing tools (e.g., `phpunit`) to verify edge cases, such as empty arrays or division by zero in `bcdivmod`.
Are there alternatives to this polyfill for Laravel-specific use cases?
For Laravel-specific needs, you could write custom helper functions (e.g., `array_find` mimics) or use packages like `spatie/array-to-xml` for array manipulation. However, this polyfill is the most robust solution for backporting PHP 8.4 features, as it’s actively maintained by Symfony and integrates seamlessly with Laravel’s core. It’s ideal if you need official, battle-tested functionality without reinventing the wheel.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai