fix(php): resolve PHP 8.4/8.5 deprecations#1486
Conversation
PHP 8.4 deprecates implicitly nullable parameter types (parameters with a default of `null` that don't explicitly declare `?Type`). This adds the `?` marker to every affected signature across `modules/`, including a related "optional-before-required" fix in PluginRollback's `suggestVersionValues()`. Also fixes one PHP 8.5 deprecation: using `null` as an array offset in `Cms\Classes\Page::getLayoutOptions()` (PHP already coerced it to `""`, so runtime behavior is unchanged). All changes use the `?Type` syntax available since PHP 7.1 and remain compatible with the project's `php >=8.1` floor. Refs: - https://www.php.net/manual/en/migration84.deprecated.php - https://www.php.net/manual/en/migration85.deprecated.php
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (19)
WalkthroughThis pull request adds explicit nullable type hints ( Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Audited the codebase for PHP 8.4 and PHP 8.5 deprecations by running
php84 -lon every PHP file undermodules/andplugins/(1,075 files) and grepping for documented deprecation patterns. All fixes use the?Typesyntax available since PHP 7.1 and remain compatible with the project'sphp >=8.1floor.PHP 8.4 — implicit nullable parameters
PHP 8.4 deprecates parameters with a default of
nullthat don't explicitly declare?Type. Fixed in:modules/backend/traits/PreferenceMaker.php:45getUserPreference(?string $key = null, …)modules/backend/behaviors/ListController.php:425,442,455listRefresh,listGetWidget,listGetConfigmodules/backend/widgets/MediaManager.php:1195,1319getThumbnailParams,deduplicatePathmodules/system/classes/FileManifest.php:57__construct(?string $root = null, ?array $modules = null)modules/system/classes/SourceManifest.php:46__construct(?string $source = null, ?string $forks = null, …)modules/system/classes/MarkupManager.php:55makeBaseTwigEnvironment(?LoaderInterface $loader = null, …)modules/system/tests/fixtures/plugins/winter/tester/components/Categories.php:8__construct(?CodeBase $cmsObject = null, …)modules/system/tests/fixtures/plugins/winter/tester/components/Comments.php:11__construct(?CodeBase $cmsObject = null, …, ?Users $users = null)modules/cms/classes/Controller.php:1589setComponentContext(?ComponentBase $component = null)modules/cms/classes/ComponentBase.php:85__construct(?CodeBase $cmsObject = null, …)modules/cms/classes/CmsException.php:45__construct(…, ?Throwable $previous = null)modules/cms/classes/Page.php(see 8.5 section)modules/cms/models/ThemeExport.php:62save(?array $options = null, …)modules/cms/models/ThemeImport.php:67save(?array $options = null, …)modules/cms/controllers/ThemeOptions.php:105getDirName(?string $dirName = null)modules/cms/twig/Extension.php:131,139,199assetsFunction,placeholderFunction,displayBlockPHP 8.4 — optional-before-required parameter
modules/system/console/PluginRollback.php:79:suggestVersionValues(string $value = null, array $allInput)had two deprecations stacked — implicit nullable type and optional parameter before a required one (deprecated since PHP 8.0). The PHP 8.4 migration guide's recommended fix is to drop the default and keep the nullable type. Laravel's Console always invokessuggestValueswith both arguments, so the default was never needed:PHP 8.5 —
nullarray offsetmodules/cms/classes/Page.php:86used$result[null] = Lang::get('cms::lang.page.no_layout'). PHP 8.5 deprecatesnullas an array offset; PHP already coerced it to''at runtime, so the behavior is identical:Docblock hygiene
Also updated
@methodannotations on theBackendandCmsfacades to match the new nullable syntax for clarity (no runtime impact):modules/backend/facades/Backend.php:7-12modules/cms/facades/Cms.php:6Summary by CodeRabbit
null, enabling enhanced IDE autocomplete, more accurate static type analysis, and clearer API contracts for developers.