fix: explicit nullable parameters for PHP 8.4 compatibility - #305
Open
chrismshea wants to merge 1 commit into
Open
fix: explicit nullable parameters for PHP 8.4 compatibility#305chrismshea wants to merge 1 commit into
chrismshea wants to merge 1 commit into
Conversation
PHP 8.4 deprecates implicit-nullable parameters (`Type $arg = null`)
and requires explicit nullable syntax (`?Type $arg = null`). In
Magento developer mode (which promotes E_DEPRECATED to thrown
exceptions) these notices cause bin/magento CLI commands to abort
before producing output (setup:upgrade, deploy:mode:show,
index:status, module:status all affected).
Updated 10 occurrences across:
- Block/Customer/Subscriptions.php
- Block/Vault/Edit/BillingAddress.php
- Model/Config/{OrderCallback,ThirdPartyPayment}.php
- Platform/Service/Transaction.php
- Service/OrderCallback/ResponseProcessor.php
Verified on Magento 2.4.8 + PHP 8.4.21 with developer mode and stock
app/bootstrap.php (error_reporting(E_ALL)). All four affected CLI
commands now run to completion with no output noise.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PHP 8.4 deprecates implicit-nullable parameters (
Type $arg = null) — the explicit nullable syntax (?Type $arg = null) is now required. This PR adds the?prefix to every typed nullable-default parameter in the module.Why this matters
Beyond eventual PHP 9 fatal removal, the immediate impact is in Magento developer mode, where Magento's error handler promotes
E_DEPRECATEDnotices into thrown exceptions. Anybin/magentoCLI command aborts before producing output. Affected commands includesetup:upgrade,deploy:mode:show,index:status, andmodule:status— meaning a merchant upgrading to 2.4.8 + PHP 8.4 in developer mode (a normal upgrade workflow) cannot run setup commands at all without this fix or a workaround.Changes
10 occurrences updated across:
Block/Customer/Subscriptions.php— constructor?Serializer\Json $serializer = nullBlock/Vault/Edit/BillingAddress.php—render(?PaymentProfileInterface $profile = null)Model/Config/OrderCallback.php—getSharedSecret(?string $websiteCode = null),isLogEnabled(?string $websiteCode = null)Model/Config/ThirdPartyPayment.php—isAllowed(?int $storeId = null),getAllowedMethods(?int $storeId = null)Platform/Service/Transaction.php—authorizeByToken,purchaseByToken,capture,credit(4?AddressInterface/?TransactionInterfaceparameters)Service/OrderCallback/ResponseProcessor.php—execute(..., ?OrderInterface $order = null)Compatibility
?Type $arg = nullis fully backward-compatible with the previous signature for both callers and subclasses. No behavior change; this is purely a syntax modernization.Verification
php -lclean across all 240+ module PHP files on PHP 8.4.21app/bootstrap.phpwitherror_reporting(E_ALL)):bin/magentocommands abort with no outputDependency
Pairs with
subscribepro/subscribepro-php#XX(SDK has 13 of its own deprecations that surface independently). Both PRs are required to fully resolve developer-mode CLI noise; merging only one leaves the other repo's deprecations active.