You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use the PHP 8.3 to 8.5 functions through the Symfony polyfills, and configure Rector accordingly #299
withPhpVersion(PHP_85) lets Rector use PHP 8.5 features. This is how array_any() (PHP 8.4) was introduced in ProcessConfiguration by #185, without requiring its polyfill: it only worked because symfony/monolog-bundle installed symfony/polyfill-php84, and it broke the lowest CI job of #269 once this package became optional (replaced by a loop in #296).
The goal is to use the functions of the latest PHP versions (8.3 to 8.5) safely, through the Symfony polyfills, while keeping PHP 8.2 as the minimum version for the syntax.
Proposed fix
composer.json: require symfony/polyfill-php83, symfony/polyfill-php84 and symfony/polyfill-php85 (^1.33). They are empty on the PHP versions that have the functions natively. They give for instance json_validate(), mb_str_pad(), str_increment() (8.3), array_find(), array_find_key(), array_any(), array_all(), mb_trim(), mb_ucfirst() (8.4), array_first(), array_last(), get_error_handler() (8.5).
rector.php:
withPhpVersion(PhpVersion::PHP_82), the minimum supported version, so that no syntax above PHP 8.2 is used (readonly classes are fine; no typed class constants, property hooks, pipe operator...);
withPhpSets() without explicit version (read from composer.json). With withPhpSets(), Rector adds its PHP_POLYFILLS set: the rules using a function of a newer version are applied when composer.json requires the matching symfony/polyfill-phpXX package. An explicit php82: true would be a ceiling and skip them;
remove LevelSetList::UP_TO_PHP_82, redundant with withPhpSets().
Apply Rector. Checked on main (Rector 2.7) with this configuration: only ForeachToArrayAnyRector applies, on the loop of ProcessConfiguration::getDependencyGroups() (back to array_any(), now with its polyfill). The PHP 8.5 rule ArrayFirstLastRector (e.g. $array[array_key_first($array)] → array_first($array)) is not polyfill-aware in Rector yet, so the PHP 8.5 functions can only be used manually for now.
CI: the lowest job (PHP 8.2) checks that the polyfills are installed.
Then the same change in the bridge bundles (archive, cache, doctrine, flysystem, rest, soap, ui), one ticket each.
Requirements
Documentation updates
Reference
Cookbooks
Changelog
Unit tests
Breaking changes
None: three new small dependencies (polyfills), no change of the minimum PHP version.
Activity
#299 - Use array_first() instead of reset() / current()
Merge pull request #300 from cleverage/299