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 Laravel Package

symfony/polyfill-php84

Symfony Polyfill for PHP 8.4 features on older runtimes. Adds helpers like array_find/array_any/array_all, bcdivmod, Deprecated attribute, fpow, grapheme_str_split, mb_* trim/ucfirst/lcfirst, ReflectionConstant, and CURL HTTP/3 constants.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install the package: Run composer require symfony/polyfill-php84. No additional setup is required—autoloading is handled automatically by Composer.
  2. First use case: Use modern PHP 8.4+ array functions (array_find, array_any, etc.) in your Laravel app while targeting PHP 8.1+ (or even 8.0, per polyfill docs). For example:
    $result = array_find($users, fn($user) => $user->isActive());
    
    This works identically to PHP 8.4’s native implementation, even on older PHP versions.

Implementation Patterns

  • Laravel Collection compatibility: While Eloquent and Collections don’t directly use these functions, you can use them in service classes or domain logic to write more expressive, functional-style code without polyfills like Illuminate\Support\Arr::first()—especially useful for cross-framework or multi-version projects.
  • Dependency injection safety: Since polyfills are auto-loaded via Composer’s classmap, you don’t need to bind services or register providers. Simply call the functions globally (e.g., bcdivmod($a, $b, 2)).
  • Testing compatibility: Write unit tests that assume PHP 8.4+ behavior without worrying about environment differences—polyfill ensures consistent behavior across local, CI, and production PHP versions.
  • Backward compatibility layering: When upgrading PHP gradually (e.g., from 8.1 → 8.4), use this polyfill to eliminate migration friction in shared libraries or mono-repos.

Gotchas and Tips

  • No namespace involvement: Functions are added to the global namespace (e.g., grapheme_str_split()), so avoid naming conflicts with custom functions.
  • Performance caveats: Polyfills use userland implementations—avoid heavy use in tight loops where native performance is critical (e.g., in batch processing of large arrays). Benchmark with array_all vs. manual foreach.
  • Deprecated attribute usage: The polyfill only enables the #[Deprecated] attribute to function as a hint—it does not emit deprecation warnings automatically. You still need to handle deprecation logic yourself (e.g., using trigger_deprecation()).
  • Intl/grapheme requirements: grapheme_str_split() and mb_* polyfills may fall back to less robust implementations if ext-intl/ext-gettext aren’t installed. Ensure production environments meet polyfill requirements (check bootstrap.php in the package).
  • Upgrade safety: When your app runs on PHP ≥8.4, Symfony’s polyfill transparently yields to native implementations—no change needed. Use function_exists('array_any') to conditionally polyfill only when needed (rarely required, but useful for custom bootstrap layers).
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4