symfony/polyfill-php83
Symfony Polyfill for PHP 8.3 features on older runtimes. Adds json_validate, Override attribute, mb_str_pad, str_increment/str_decrement, updated LDAP/stream context signatures, Date/SQLite3 exception classes, and more.
symfony/polyfill-*), requiring no architectural changes. It leverages Laravel’s autoloader and composer ecosystem without conflicts.json_validate replaces manual JSON parsing in API request handling (e.g., Illuminate\Http\Request payloads).str_increment/str_decrement simplifies versioning logic (e.g., vendor:package@1.0.0 increments).DateTimeException, SQLite3Exception) align with Laravel’s Illuminate\Support\Facades\Log and App\Exceptions\Handler.ldap_exop_sync) enable gradual migration from legacy systems.composer.json with no build step changes. Works with Laravel Mix/Vite, Forge, and Valet.composer require symfony/polyfill-php83 --dry-run
str_increment) can be wrapped in custom helpers for consistency:
// app/Helpers/StringHelper.php
use Symfony\Polyfill\Php83\StringFunctions;
if (!function_exists('laravel_str_increment')) {
function laravel_str_increment(string $str): string {
return StringFunctions::str_increment($str);
}
}
str_increment with PHP_INT_MAX strings). Mitigate with:
json_validate and str_increment. Critical for:
str_increment for job IDs).// phpstan.neon
parameters:
level: 8
checkMissingIterableValueType: false
checkMissingReturnType: false
symfony:
polyfills: true
composer.json:
"config": {
"platform": {
"php": "8.1"
}
}
Override for trait method overrides in Laravel 11+.)json_validate) be adopted via Laravel’s infrastructure (e.g., platform PHP upgrades)?phpunit) that can adopt polyfill-specific assertions?require (production) or require-dev (testing only)?symfony/polyfill-* packages? (E.g., php80, php81.)composer remove or feature flags.)composer why symfony/polyfill-php83.)Override attribute).symfony/var-dumper, symfony/console). No conflicts expected.str_increment can generate unique IDs for search engines.grep -r "str_increment\|json_validate\|Override" app/
app/Http/Controllers, string manipulation in app/Models).composer.json:
"require": {
"symfony/polyfill-php83": "^1.38"
}
composer update symfony/polyfill-php83 --with-dependencies.json_validate in app/Http/Middleware/ValidateRequests.php:
use Symfony\Polyfill\Php83\JsonValidate;
if (!JsonValidate::validate($request->json()->all())) {
abort(422, 'Invalid JSON payload.');
}
str_increment in app/Models/VersionedModel.php:
use Symfony\Polyfill\Php83\StringFunctions;
$nextVersion = StringFunctions::str_increment($this->version);
app/Exceptions/Handler.php:
use Symfony\Polyfill\Php83\DateTimeException;
DateTimeException).json_validate in API endpoints).config('features.use_polyfill_str_increment')).// .idea/php_stubs.php
<?php
namespace Symfony\Polyfill\Php83 {
class JsonValidate {}
class StringFunctions {}
}
settings.json:
"intelephense.stubs": ["vendor/symfony/polyfill-php83/stubs"]
phpunit.xml:
<phpunit>
<extensions>
<extension class="Symfony\Polyfill\Php83\Tests\JsonValidateTestCase"/>
</extensions>
</phpunit>
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
extensions: mbstring, json
composer.json and verify no regressions via:
composer validate && composer install --prefer-dist --no-interaction
str_increment logic) with polyfilled versions.Override attribute in new classes.How can I help you explore Laravel packages today?