- How do I add symfony/polyfill-php81 to a Laravel project?
- Run `composer require symfony/polyfill-php81` in your project root. No additional configuration is needed—it auto-detects missing PHP 8.1 features and polyfills them at runtime. Ensure your `composer.json` specifies a minimum PHP version of 7.4+ if using CURLStringFile.
- Does this package work with Laravel 9/10 on PHP 7.4?
- Yes, it fully supports Laravel 9.x–10.x on PHP 7.4+. All features except `CURLStringFile` work on PHP 7.4, while `CURLStringFile` requires PHP ≥7.4 (it fails silently on older versions). Test your app on your target PHP version to confirm behavior.
- Will this break existing code that checks for PHP 8.1 features manually?
- No, the polyfill replaces missing functions at runtime, so manual checks like `function_exists('array_is_list')` will now return `true` even on PHP <8.1. Remove redundant conditional logic after adding the polyfill to avoid double-checks.
- Are there any performance concerns with using this polyfill?
- The performance impact is negligible—polyfills add ~0–5ms per call. Benchmark your critical paths if needed, but most Laravel apps won’t notice a difference. The overhead is justified by the flexibility of supporting older PHP versions.
- Can I use enum_exists() in Laravel’s service container or facades?
- Yes, the polyfill works seamlessly with Laravel’s dependency injection and facades. Use `enum_exists()` in service providers, controllers, or validation rules just like native PHP 8.1. No special setup is required.
- What happens if I already have a custom polyfill for array_is_list?
- Conflicts may occur if your custom polyfill or legacy code overrides the same functions. Audit your codebase for duplicate implementations (e.g., `array_is_list`) before adding this package. The Symfony polyfill prioritizes its own definitions.
- Does this package support PHP 7.2 or 7.3 for all features?
- No, `CURLStringFile` is only supported on PHP ≥7.4. Other features (e.g., `array_is_list`, `enum_exists`) work on PHP 7.2–7.3, but test thoroughly if targeting those versions. Enforce PHP ≥7.4 in `composer.json` if you need `CURLStringFile`.
- How do I test that the polyfill works correctly in CI?
- Add tests for polyfilled functions across your target PHP versions. For example, verify `array_is_list([])` returns `true` on PHP 7.4 and 8.1. Use Docker or CI matrix testing to cover multiple PHP versions. Symfony’s polyfill suite is widely tested, but validate your app’s specific use cases.
- Are there alternatives to symfony/prubberducky/php-polyfill?
- No direct alternative exists for this exact scope, but you could manually implement polyfills or use `php-polyfill` packages like `rubberducky/php-polyfill`. However, Symfony’s polyfill is more maintainable, Laravel-compatible, and actively updated. It’s the recommended choice for PHP 8.1 feature backporting.
- Will this package work with Laravel’s validation rules or Form Requests?
- Absolutely. Use polyfilled functions like `array_is_list()` in custom validation rules or Form Requests. For example, validate arrays with `array_is_list($data)` in a `Rule` class. The polyfill integrates transparently with Laravel’s validation pipeline.