-
-
Notifications
You must be signed in to change notification settings - Fork 452
PHP8.5: fix null array offset #5028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR addresses null array offset deprecation warnings in PHP 8.5 by adding null checks and type coercion before array access operations. The changes prevent potential issues where null values are used as array keys or offsets.
Key Changes:
- Added null checks with empty string fallback before array key access in multiple methods
- Added explicit string type casting for array keys to prevent null offset warnings
- Removed a potentially problematic
curl_close()call that could fail if the resource was already null
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/Varien/Http/Adapter/Curl.php | Removed curl_close call to prevent errors when resource is null |
| lib/Varien/Data/Collection.php | Added null check converting null to empty string before array access |
| app/code/core/Mage/Index/Model/Indexer/Abstract.php | Added null check converting null to empty string before array access |
| app/code/core/Mage/Core/Controller/Varien/Router/Standard.php | Added string cast to prevent null as array key |
| app/code/core/Mage/CatalogInventory/Model/Stock/Status.php | Added string cast to prevent null as array key |
| app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Price.php | Added null check converting null to empty string before array access |
| app/code/core/Mage/Catalog/Model/Product/Type.php | Added string cast to prevent null as array key |
Comments suppressed due to low confidence (1)
app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Price.php:1
- Converting null to empty string will result in a less informative error message on line 319 ('Unsupported product type ""'). Consider checking for null explicitly and throwing a more specific exception like 'Product type ID cannot be null' to aid debugging.
<?php
| $this->load(); | ||
|
|
||
| if ($idValue === null) { | ||
| $idValue = ''; |
Copilot
AI
Oct 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converting null to an empty string could mask logic errors where null IDs are passed unintentionally. Consider adding validation to throw an exception or log a warning when null is passed, or return null immediately instead of treating it as a valid key. This would make debugging easier and prevent unexpected behavior where null and empty string IDs are treated as equivalent.
| $idValue = ''; | |
| return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| */ | ||
| public function matchEntityAndType($entity, $type) | ||
| { | ||
| if ($entity === null) { | ||
| $entity = ''; |
Copilot
AI
Oct 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converting null entity to an empty string could hide incorrect method calls. Consider adding type hints (e.g., ?string $entity) and either returning early with a default value or throwing an exception when null is passed, as null likely indicates invalid usage rather than a valid empty entity name.
| */ | |
| public function matchEntityAndType($entity, $type) | |
| { | |
| if ($entity === null) { | |
| $entity = ''; | |
| * @throws InvalidArgumentException if $entity is null | |
| */ | |
| public function matchEntityAndType(?string $entity, string $type) | |
| { | |
| if ($entity === null) { | |
| throw new InvalidArgumentException('Entity name must not be null.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
| if ($productTypeId === null) { | ||
| $productTypeId = ''; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not like this?
$productTypeId ??= '';



https://github.com/OpenMage/magento-lts/actions/runs/18709139113/job/53353233192