symfony/polyfill-php85
Symfony Polyfill for PHP 8.5 features on older runtimes. Adds get_error_handler/get_exception_handler, NoDiscard attribute, array_first/array_last, DelayedTargetValidation, Filter exceptions, and locale_is_right_to_left. MIT licensed.
array_first in Collections, NoDiscard in attribute-based logic) without forcing a full stack upgrade. Critical for monolithic Laravel apps with mixed PHP version constraints (e.g., shared hosting, third-party services).array_first/array_last simplify Laravel’s Collection methods (e.g., replacing ->first() in edge cases like ->where()->first()).FilterException enhances Laravel’s Validator by converting filter failures into exceptions, improving security and debugging (aligns with Symfony’s validation patterns).NoDiscard and DelayedTargetValidation integrate with Laravel’s attribute system (e.g., #[NoDiscard] for critical methods), preparing for Laravel 11+ features.get_error_handler/get_exception_handler improves observability in legacy Laravel apps, aiding compliance (e.g., PCI-DSS, GDPR).symfony/polyfill-php80/php81, adding php85 maintains consistency and reduces maintenance overhead from custom polyfills.symfony/polyfill-php85) and use PHP 8.5+ syntax directly (e.g., array_first($array)).spatie/laravel-permission, tightenco/ziggy). No known conflicts, but validate with:
composer require symfony/polyfill-php85 && composer validate
NoDiscard/DelayedTargetValidation require PHP 8.0+. Test across PHP 8.0–8.4 using PHPUnit data providers:
public function testNoDiscardAttribute() {
$this->markTestSkipped('Requires PHP 8.0+');
// Test logic
}
array_first on empty arrays and FilterException in FormRequest validation:
public function rules() {
return ['email' => 'required|email:filter,throw_exception'];
}
vendor/symfony/polyfill-php85.NoDiscard:
parameters:
attributes:
knownAttributes:
- Symfony\Component\Polyfill\Php85\NoDiscard
locale_is_right_to_left requires the intl extension). Validate with:
php -m intl || composer require ext-intl
NoDiscard/DelayedTargetValidation might clash with Laravel’s attributes (e.g., HasFactory). Test with:
php artisan make:model TestModel --factory && php artisan make:model TestModel --attribute
array_first) using:
composer require --dev blackfire/blackfire && vendor/bin/blackfire run php artisan route:list
memory_get_usage(true) // Before/after critical operations
composer post-update script:
"scripts": {
"post-update": "php -r \"if (file_exists(__DIR__.'/vendor/symfony/polyfill-php85')) echo 'WARNING: polyfill-php85 may be unused after PHP 8.5 upgrade.\\n';\""
}
FilterException: Changes error-handling semantics. Ensure FormRequest validation handles exceptions:
try {
$validator = Validator::make($request->all(), $rules);
if ($validator->fails()) {
throw new FilterException($validator->errors());
}
} catch (FilterException $e) {
return back()->withErrors(['filter' => $e->getMessage()]);
}
get_error_handler may conflict with Laravel’s App\Exceptions\Handler. Audit custom error handlers.NoDiscard for new APIs, array_first for performance-critical paths)?NoDiscard/DelayedTargetValidation attributes?laravel/breeze, laravel/sanctum).array_first/array_last integrate seamlessly with Laravel’s Illuminate\Support\Collection.FilterException aligns with Laravel’s Validator and Symfony’s Filter component.NoDiscard/DelayedTargetValidation work with Laravel’s attribute system (e.g., #[NoDiscard] in DTOs).vendor/ (negligible compared to Laravel’s ~50MB).php -v) and Laravel dependencies (composer show).array_first in API controllers, NoDiscard in auth logic).intl extension for locale_is_right_to_left:
How can I help you explore Laravel packages today?