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.
Pros (Updated/Reinforced):
mb_* polyfills (e.g., #603, #591) address edge cases like null input handling and Unicode awareness, improving reliability for Laravel’s Str helpers and form validation.grapheme_str_split (bug #598) ensures consistency across environments with older PCRE versions (e.g., shared hosting), reducing deployment friction.ReflectionConstant stub issues (bug #600) mitigates risks in Laravel’s introspection-heavy components (e.g., service containers, dynamic method calls).#590), aligning with modern security practices.Cons (Updated):
grapheme_str_split fix introduces a dependency on PCRE ≥10.44, which may not be available on legacy systems (e.g., very old shared hosting).ReflectionConstant fix for PDO attributes adds subtle behavioral changes that could affect Laravel’s database migrations or Eloquent internals if not tested thoroughly.Laravel-Specific Risks (Updated):
Illuminate\Database) may rely on PDO stubs for SSL or connection handling. The fix for #590 could introduce subtle changes in error handling or connection pooling.mb_* fixes (e.g., #591) are critical for Laravel’s Str::of() and localization features but may expose inconsistencies if the application relies on custom mbstring logic.grapheme_str_split fix could break applications deployed on hosts with PCRE <10.44, requiring pre-deployment checks (e.g., php -r "echo PCRE_VERSION;").Technical Risks (Updated):
ReflectionConstant stub fix might introduce minor performance overhead in Laravel’s service container or dynamic proxy generation (e.g., Eloquent relationships).Strategic Alignment:
grapheme_str_split fix may not be applicable without upgrades.Laravel-Specific Impact:
#600 could affect dynamic property access.mbstring logic (e.g., in form requests or validation)? The fixes for #603 and #591 may require validation.Testing and Validation:
mb_rtrim() with Unicode characters (bug #591).grapheme_str_split() on strings with mixed scripts (e.g., CJK + Latin).if (version_compare(PCRE_VERSION, '10.44') < 0) {
throw new \RuntimeException('PCRE ≥10.44 required for grapheme_str_split polyfill.');
}
Performance and Scaling:
Maintenance and Governance:
"symfony/polyfill-php84": "^1.38.0", // Explicitly target the fixed version
grapheme_str_split fixes.Alternatives and Trade-offs:
.env (e.g., DB_SOCKET=/path/to/socket) as an alternative to polyfills.Str::of() or Illuminate\Support\Stringable as higher-level abstractions.Dependency Management:
symfony/polyfill-intl), especially if using mb_* functions.spatie/array-to-object) for indirect polyfill dependencies.Updated Laravel Compatibility Matrix:
| Polyfill Feature | Laravel Integration Point | Risk Level | Notes |
|---|---|---|---|
mb_* fixes (#603, #591) |
Str::of(), form validation, localization |
Low | Critical for Unicode handling. |
grapheme_str_split fix (#598) |
Localization, multibyte string processing | High | PCRE ≥10.44 required. |
ReflectionConstant stub (#600) |
Service container, dynamic method calls | Medium | Minor reflection overhead. |
PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT (#590) |
Database migrations, Eloquent | Medium | SSL connection behavior may change. |
Symfony Component Synergy (Updated):
mb_* fixes may already be covered, reducing redundancy.PDO fix (#590) could interact with Symfony’s Doctrine bridge if both are used.PHP Version Targeting (Updated):
Pre-Integration Audit:
php -r "if (version_compare(PCRE_VERSION, '10.44') < 0) exit(1);"
mb_* and PDO usage:
phpstan analyse --level=max --configuration=php84-rules.neon
Pilot Phase:
composer.json to target the fixed version:
"require-dev": {
"symfony/polyfill-php84": "^1.38.0"
}
PDO SSL fix in a staging environment with:
// Test SSL connection attributes
$pdo = new PDO('mysql:host=...', 'user', 'pass', [
PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => true,
]);
$this->assertTrue($pdo->getAttribute(PDO::ATTR_PERSISTENT));
mb_* fixes with edge cases:
// Test mb_rtrim with null and Unicode
$this->assertEquals('', mb_rtrim(null, ' ', 'UTF-8'));
$this->assertEquals('test', mb_rtrim("test\u{3000}", ' ', 'UTF-8')); // CJK space
Gradual Rollout:
mbstring logic with the polyfilled versions.try {
Schema::create('...', function (Blueprint $table) {
// ...
});
} catch (PDOException $
How can I help you explore Laravel packages today?