magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.47k stars 9.28k forks source link

Magento_Theme title.phtml template invalid for PHP 8.2 #39092

Open adamlavery opened 3 weeks ago

adamlavery commented 3 weeks ago

Preconditions and environment

OS 2.4.7

Steps to reproduce

There's a code error in vendor\magento\module-theme\view\frontend\templates\html\title.phtml

Expected result

Should be written for PHP 8.2 but is not.

Actual result

Template crashes if there's no page title.

Additional information

This code:

if (trim($block->getPageHeading())) {
    $titleHtml = '<span class="base" data-ui-id="page-title-wrapper" '
        . $block->getAddBaseAttribute()
        . '>'
        . $block->escapeHtml($block->getPageHeading())
        . '</span>';
}

Needs correcting to:

if ($block->getPageHeading()) {
    $titleHtml = '<span class="base" data-ui-id="page-title-wrapper" '
        . $block->getAddBaseAttribute()
        . '>'
        . $block->escapeHtml(trim($block->getPageHeading()))
        . '</span>';
}

Release note

Fix code that fails with PHP 8.2

Triage and priority

m2-assistant[bot] commented 3 weeks ago

Hi @adamlavery. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

hostep commented 2 weeks ago

It would help if you could specify the error message you're seeing? But I guess it happens when $block->getPageHeading() returns null and not a string?

adamlavery commented 2 weeks ago

@hostep sorry, didn't think a log of this error was necessary. Yes, as of PHP 8.? you can no longer pass null to most/all PHP string functions. I'm sure there must be a valid reason for this change which breaks code all over the place, although I can't see it!!

m2-assistant[bot] commented 2 weeks ago

Hi @engcom-November. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-November commented 2 weeks ago

Hello @adamlavery,

Thank you for the report and collaboration!

If the function $block->getPageHeading() returns null by any case which it should not, will cause the error as php string functions won't accept null as parameter. Hence confirming this.

github-jira-sync-bot commented 2 weeks ago

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-12856 is successfully created for this GitHub issue.

m2-assistant[bot] commented 2 weeks ago

:white_check_mark: Confirmed by @engcom-November. Thank you for verifying the issue.
Issue Available: @engcom-November, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.