Closed
Description
This issue is automatically created based on existing pull request: #28797: Fixed 'Undefined class constant' error when interceptor is generated.
Summary (*)
- Magento 2.4-develop
- Since constant is declared as private it's not accessible from parent classes.
- Since it used with
static
keyword, PHP will search it within class instance. - Class instance will be an instance of generated
Interceptor
without access to private variables of child classes. - This will lead to an 'Undefined class constant' error.
Examples (*)
-
Create a plugin for
Magento\Theme\Block\Html\Title
class:<type name="Magento\Theme\Block\Html\Title"> <plugin name="titlePlugin" type="Magento\Theme\Plugin\TitlePlugin" /> </type>
<?php namespace Magento\Theme\Plugin; class TitlePlugin { /** * @param mixed $subject * @param mixed $result * @return mixed */ public function afterGetPageHeading( $subject, $result ) { return $result; } }
-
Open frontend.
-
You'll see an error:
Error: Undefined class constant 'XML_PATH_HEADER_TRANSLATE_TITLE' in app/code/Magento/Theme/Block/Html/Title.php:104 Stack trace: #0 app/code/Magento/Theme/Block/Html/Title.php(82): Magento\Theme\Block\Html\Title->shouldTranslateTitle() #1 generated/code/Magento/Theme/Block/Html/Title/Interceptor.php(32): Magento\Theme\Block\Html\Title->getPageHeading() #2 app/code/Magento/Theme/view/frontend/templates/html/title.phtml(12): Magento\Theme\Block\Html\Title\Interceptor->getPageHeading() ...
Proposed solution
Another way to solve this bug - is to declare constant as public instead of private.
If you think it should be public - I'll update PR.
Metadata
Metadata
Assignees
Labels
The issue has been fixed in 2.4-develop branchGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 1 Passed. Automatic verification of issue format passedGate 4. Acknowledged. Issue is added to backlog and ready for developmentNo current plan to fix. Fixing can be deferred as a logical part of more important work.Indicates original Magento version for the Issue report.The issue has been reproduced on latest 2.4-develop branchAffects non-critical data or functionality and does not force users to employ a workaround.Has been reviewed and prioritized during Triage with Product Managers
Type
Projects
Status
Done