fix: replace PHP 8.5 array_last() with array_key_last()-based compat #90
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.
Env
Magento: 2.4.7-p7
PHP: 8.2.29
Module: unzerdev/magento2 4.0.0
Problem
The code uses array_last() which is only available in PHP 8.5. The package declares compatibility with PHP 7.4 / 8.1 / 8.2 / 8.3 / 8.4, so this throws a fatal on ≤8.4.
Fix
Replace
array_last($arr) with ($arr === []) ? null : $arr[\array_key_last($arr)], which preserves the same semantics (null for empty arrays) and works on PHP 7.4–8.4.Notes
array_last() was introduced in PHP 8.5. Ref: php.watch / RFC.
Tested locally on PHP 8.2; no behavior change besides removing fatal.
No public API changes.
PHP 8.2 error message
main.CRITICAL: Error: Call to undefined function Unzer\PAPI\Model\Command\array_last() in /magento2/vendor/unzerdev/magento2/Model/Command/TransactionSynchronizer.php:42