symfony/polyfill-php83
Symfony Polyfill for PHP 8.3 features on older runtimes. Provides json_validate, Override attribute, mb_str_pad, str_increment/str_decrement, Date* exceptions, SQLite3Exception, and updated ldap/stream context APIs.
Laravel Ecosystem Synergy: Perfectly aligns with Laravel’s reliance on Symfony components (e.g., HTTP client, process, polyfills). The package’s design mirrors Laravel’s dependency management patterns, requiring zero architectural refactoring. Key Laravel layers benefit:
json_validate integrates seamlessly with Illuminate\Http\Request for payload validation.Illuminate\Validation for stricter JSON schema enforcement.str_increment/str_decrement simplifies versioning in app/Models or app/Services.SQLite3Exception, DateTimeException) align with Laravel’s App\Exceptions\Handler.ldap_exop_sync) enable gradual migration from older Laravel packages (e.g., spatie/laravel-activitylog).Feature Prioritization:
json_validate (API security), Override (IDE support), str_increment (versioning).mb_str_pad (multibyte strings), DateTimeException (error handling).PHP Version Targeting:
Stack Compatibility:
mb_str_pad and Override attribute support.Override attribute (requires PHP 8.0+).Migration Path:
composer require symfony/polyfill-php83 --dev
DateTimeException in App\Exceptions\Handler).json_validate in API controllers, str_increment in versioning).Override attribute in custom traits).str_increment edge cases).json_validate in API endpoints.Compatibility Risks:
Override attribute (requires PHP 8.0+).json_validate).ldaprecord/ldaprecord or custom stream wrappers.Low Risk:
v1.38.x).json_validate; negligible for others).Moderate Risk:
Override attribute may require PHPStorm/VSCode updates for full autocompletion.str_increment with numeric strings beyond PHP_INT_MAX.mb_str_pad with invalid encodings (fixed in v1.38.1).Mitigation Strategies:
if (function_exists('json_validate'))).UPGRADING.md with polyfill usage examples.PHP Version Strategy:
Feature Prioritization:
json_validate for API security vs. Override for IDE support).json_validate logic)?Integration Scope:
Testing & Monitoring:
json_validate in API routes)?Long-Term Maintenance:
v1.39.0)?Laravel-Specific Synergies:
Illuminate\Http\Request with json_validate for stricter payload validation.Illuminate\Validation\Rules with polyfill-backed rules (e.g., JsonValid).str_increment in app/Models for versioned records (e.g., SoftwareVersion).RuntimeException) with DateTimeException or SQLite3Exception in App\Exceptions\Handler.app/Helpers/StringHelper.php):
if (!function_exists('laravel_str_increment')) {
function laravel_str_increment(string $str): string {
return \Symfony\Polyfill\Php83\str_increment($str);
}
}
Symfony Ecosystem:
symfony/polyfill-* (e.g., symfony/polyfill-mbstring).Non-Laravel Considerations:
spatie/laravel-activitylog, laravel-ldap/ldap) for LDAP/stream polyfills.Assessment Phase:
json_validate for APIs, str_increment for versioning).Dependency Addition:
composer.json:
"require-dev": {
"symfony/polyfill-php83": "^1.38"
}
composer update symfony/polyfill-php83 --with-dependencies.Incremental Adoption:
DateTimeException in App\Exceptions\Handler).
use Symfony\Polyfill\Php83\DateTimeException;
throw new DateTimeException('Invalid date format');
json_validate in API controllers).
use Symfony\Polyfill\Php83\JsonValidate;
if (!JsonValidate::validate($request->json()->all())) {
abort(422, 'Invalid JSON payload');
}
Override attribute in custom traits).
use Symfony\Polyfill\Php83\Override;
class CustomTrait {
#[Override]
public function method(): void {}
}
**Testing & Validation
How can I help you explore Laravel packages today?