Skip to content
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

[Issue] Fixed 'Undefined class constant' error when interceptor is generated. #28981

Closed
m2-assistant bot opened this issue Jul 3, 2020 · 14 comments · Fixed by #28797
Closed

[Issue] Fixed 'Undefined class constant' error when interceptor is generated. #28981

m2-assistant bot opened this issue Jul 3, 2020 · 14 comments · Fixed by #28797
Labels
Component: Theme Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Priority: P4 No current plan to fix. Fixing can be deferred as a logical part of more important work. Progress: done Reported on 2.4.0 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. Triage: Done Has been reviewed and prioritized during Triage with Product Managers

Comments

@m2-assistant
Copy link

m2-assistant bot commented Jul 3, 2020

This issue is automatically created based on existing pull request: #28797: Fixed 'Undefined class constant' error when interceptor is generated.


Summary (*)

  1. Magento 2.4-develop
  2. Since constant is declared as private it's not accessible from parent classes.
  3. Since it used with static keyword, PHP will search it within class instance.
  4. Class instance will be an instance of generated Interceptor without access to private variables of child classes.
  5. This will lead to an 'Undefined class constant' error.

Examples (*)

  1. 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;
        }
    }
  2. Open frontend.

  3. 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.

@m2-assistant m2-assistant bot added Component: Theme Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. labels Jul 3, 2020
@magento-engcom-team magento-engcom-team added the Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed label Jul 3, 2020
@engcom-Delta engcom-Delta self-assigned this Jul 3, 2020
@m2-assistant
Copy link
Author

m2-assistant bot commented Jul 3, 2020

Hi @engcom-Delta. 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: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@magento-engcom-team magento-engcom-team added Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed and removed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed labels Jul 3, 2020
@engcom-Delta engcom-Delta added Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed labels Jul 3, 2020
@ghost ghost unassigned engcom-Delta Jul 3, 2020
@magento-engcom-team magento-engcom-team added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Jul 3, 2020
@magento-engcom-team
Copy link
Contributor

✅ Confirmed by @engcom-Delta
Thank you for verifying the issue. Based on the provided information internal tickets MC-35619 were created

Issue Available: @engcom-Delta, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@ghost ghost added the Priority: P4 No current plan to fix. Fixing can be deferred as a logical part of more important work. label Jul 6, 2020
@motorlesha
Copy link

we have the same issue. Please fix it

@magento-engcom-team magento-engcom-team added the Triage: Done Has been reviewed and prioritized during Triage with Product Managers label Jul 15, 2020
@magento-engcom-team
Copy link
Contributor

Hi @m2-assistant[bot]. Thank you for your report.
The issue has been fixed in #28797 by @vovayatsyuk in 2.4-develop branch
Related commit(s):

The fix will be available with the upcoming 2.4.1 release.

@magento-engcom-team magento-engcom-team added the Fixed in 2.4.x The issue has been fixed in 2.4-develop branch label Jul 16, 2020
@alexey-motorny-amasty
Copy link

@magento-engcom-team why fatal error will be included only in 2.4.1 version? This is a critical error. Is any chance to include this fix into 2.4.0 version? Safe fix

@Hexmage
Copy link

Hexmage commented Jul 29, 2020

I don't understand how 2.4.0 could be released with this error in it which basically just crashes every frontend page.

@alexey-motorny-amasty
Copy link

@Hexmage we have created patch - mini module to resolve this error. Maybe it will be useful for you
https://amasty.com/knowledge-base/magento-2-4-release-undefined-class-constant-error.html

@hostep
Copy link
Contributor

hostep commented Jul 31, 2020

@alexey-motorny-amasty: out of interest (since I saw your little amasty/module-mage24fix module come in with composer when updating the improved layered navigation module on a 2.3.5 shop). This little module is tested and is backwards compatible with Magento 2.3.x I hope?

@alexey-motorny-amasty
Copy link

@hostep Yes, it is compatible, but unnecessary. do not hesitate to just delete this patch

@mdehaan
Copy link

mdehaan commented Aug 14, 2020

@Hexmage we have created patch - mini module to resolve this error. Maybe it will be useful for you
https://amasty.com/knowledge-base/magento-2-4-release-undefined-class-constant-error.html

Hi Hexmage, I have a problem with your this fix: #48 {main} [] []
[2020-08-14 13:30:16] main.CRITICAL: Error: Class 'Amasty\Mage24Fix\Block\Theme\Html\Title' not found in /public_html/generated/code/Amasty/Mage24Fix/Block/Theme/Html/Title/Interceptor.php:7

@Hexmage
Copy link

Hexmage commented Aug 14, 2020

@mdehaan not my fix contact @alexey-motorny-amasty instead.

@alexey-motorny-amasty
Copy link

@mdehaan please check if you have copied all the files. or run setup:di:compile

@mdehaan
Copy link

mdehaan commented Aug 17, 2020

@mdehaan please check if you have copied all the files. or run setup:di:compile
@alexey-motorny-amasty

I just fixed it.
I renamed module-mage24fix-master to Mage24Fix and now it works.

@magento-engcom-team
Copy link
Contributor

Hi @m2-assistant[bot]. Thank you for your report.
The issue has been fixed in #29925 by @toxix in 2.4-develop branch
Related commit(s):

The fix will be available with the upcoming 2.4.2 release.

@magento-engcom-team magento-engcom-team added the Reported on 2.4.0 Indicates original Magento version for the Issue report. label Nov 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Theme Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Priority: P4 No current plan to fix. Fixing can be deferred as a logical part of more important work. Progress: done Reported on 2.4.0 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. Triage: Done Has been reviewed and prioritized during Triage with Product Managers
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

7 participants