Skip to content

Fix PHP 8.5 "null as array offset" deprecation in AbstractPdf::_getRenderer() - #41135

Open
Bashev wants to merge 3 commits into
magento:2.4-developfrom
Bashev:php85-fix-abstractpdf-null-renderer-type
Open

Fix PHP 8.5 "null as array offset" deprecation in AbstractPdf::_getRenderer()#41135
Bashev wants to merge 3 commits into
magento:2.4-developfrom
Bashev:php85-fix-abstractpdf-null-renderer-type

Conversation

@Bashev

@Bashev Bashev commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Description

On PHP 8.5, using null as an array offset is deprecated ("Using null as an array offset is deprecated, use an empty string instead").

Magento\Sales\Model\Order\Pdf\AbstractPdf::_getRenderer() calls isset($this->_renderers[$type]) without guarding $type against null. When the renderer type resolves to null — e.g. a grouped-product order item whose getRealProductType() returns null — the isset() triggers the deprecation. In production mode, where deprecations are promoted to exceptions, PDF generation aborts (HTTP 404 / error page) instead of falling back to the default renderer.

This mirrors the other PHP 8.5 null-array-offset fixes already merged (e.g. #40889 for ScopeCodeResolver).

Fixed Issues

  1. Fixes [PHP 8.5] AbstractPdf::_getRenderer() triggers "Using null as an array offset is deprecated" (breaks PDF print) #41134

Manual testing scenarios

  1. Run Magento on PHP 8.5 in production mode (bin/magento deploy:mode:set production).
  2. Place an order containing an item whose renderer type resolves to null (e.g. an order item where getRealProductType() returns null, such as some grouped-product scenarios or data migrated from older versions).
  3. In the admin, open the invoice (or shipment/credit memo) for that order and click Print.
  4. Before the fix: PDF generation aborts with an error page (the deprecation is promoted to an exception). After the fix: the PDF is generated normally, the item is rendered with the default renderer.

Covered by a new unit test AbstractTest::testGetRendererFallsBackToDefaultForNullType(), which promotes E_DEPRECATED to an exception so a regression fails the test:

vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/Magento/Sales/Test/Unit/Model/Order/Pdf/AbstractTest.php

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

…nderer()

On PHP 8.5, using null as an array offset is deprecated. When a PDF renderer
type resolves to null (e.g. a grouped-product order item whose real product
type is null), _getRenderer() calls isset($this->_renderers[$type]) with
$type === null, emitting a deprecation at AbstractPdf.php. In production mode,
where deprecations are promoted to exceptions, PDF generation aborts.

Guard the array offset against null before the isset() check so a null type
falls back to the 'default' renderer, consistent with the other PHP 8.5
null-array-offset fixes (e.g. magento#40889).

Covered by a unit test that promotes deprecations to exceptions and asserts the
null type resolves to the default renderer (fails on the unpatched code).
@m2-assistant

m2-assistant Bot commented Aug 20, 2026

Copy link
Copy Markdown

Hi @Bashev. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.
❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

Comment thread app/code/Magento/Sales/Test/Unit/Model/Order/Pdf/AbstractTest.php Outdated
@hostep

hostep commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Also can you edit your opening post and put a link to #41134 in there, so this PR and the issue are linked together? Thanks!

@Bashev

Bashev commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

@magento run all tests

@Bashev

Bashev commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

@magento run Database Compare, Functional Tests B2B, Functional Tests CE, Functional Tests EE

@Bashev

Bashev commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

@magento run all tests

@Bashev

Bashev commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

@magento run Functional Tests CE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[PHP 8.5] AbstractPdf::_getRenderer() triggers "Using null as an array offset is deprecated" (breaks PDF print)

2 participants