Cannot Access Protected Property Joomla\CMS\Menu\MenuItem::$params - Question | JoomShaper
🎃 Halloween Sale is Live! Get 35% OFF on all plans. Sale ends soon! Get Offer

Cannot Access Protected Property Joomla\CMS\Menu\MenuItem::$params

LB

Leon Beeloo

Template 6 months ago

Technical information: PHP: 8.3.16 Joomla: 4.4.11 Template: Shaper_Spectrum (2.0.2)

Updating from Shaper_Spectrum 2.0.1 to 2.0.2 causes the following error: This error will show at the frontend of our website. Cannot Access Protected Property Joomla\CMS\Menu\MenuItem::$params

From other posts on this forum, it appears that this issue has been present for over a year.

Problem appears to be the following. Joomla defines the MenuItem class in libraries>src>menu>MenuItem.php The MenuItem class has the property params whose visibility is set to protected. line 133: protected $params;

The shaper_spectrum template tries to directly access the protected property.

ROOT>templates>shaper_spectrum>html>mod_menu>default.php line 38 contains "$item->params->get('...')" the same issue applies at line 45. directly trying to access the protected params property.

I found the following workarounds:

  1. change the property visibility from protected to public: protected $params; -> public $params; I do not know if this change could have negative security implications.

  2. defining "$params = $item->getParams(); " before line 38 in default.php and replacing both instances of $item->params with $params

alternatively, $item->params->get(... could be replaced with $item->getParams()->get(...

My understanding of PHP is limited, but I have the following questions: Since the code in default.php loops over several items, can it be assumed that all these classes will have a getParams() method, if such, could this problem be solved by the fix mentioned above.

If this is not the case, could a check be added to use the getter only when it would otherwise attempt to access a protected property?

If no fix for this issue will be implemented, could you provide advice on how to create an override for default.php?

0
9 Answers
Paul Frankowski
Paul Frankowski
Accepted Answer
Senior Staff 3 months ago #198297

Probably it will be fixed in next update.

As you probably know, all helix3 based templates have many years, and maybe you should consider template switch from Helix3 based to Helix Ultimate based, less problems in near future. It's like with Windows XP or 8 etc.

0
Toufiq
Toufiq
Accepted Answer
Senior Staff 6 months ago #190744

Hi there,

Thank you for reaching out, and I apologize for any inconvenience caused by this oversight. To better address the issue, could you kindly provide Joomla administrator access? This will enable me to thoroughly investigate the matter and provide you with a prompt resolution.

I appreciate your cooperation and will ensure to get back to you as soon as possible.

Best regards,

Toufiqur Rahman (Team Lead, Support)

0
LB
Leon Beeloo
Accepted Answer
3 months ago #197501

see below

0
Toufiq
Toufiq
Accepted Answer
Senior Staff 3 months ago #197512

Please check the screenshot.

0
LB
Leon Beeloo
Accepted Answer
3 months ago #197907
0
Toufiq
Toufiq
Accepted Answer
Senior Staff 3 months ago #198081

Now your secret links don't work.

0
LB
Leon Beeloo
Accepted Answer
3 months ago #198256
0
Paul Frankowski
Paul Frankowski
Accepted Answer
Senior Staff 3 months ago #198257

Hoi Leon,

we need Super User account, normal Administrator won't help Us, no access to files. Please correct Access level.


In general, it's very easy to fix it.

  1. Download Helix3 template (or quickstart)
  2. and replace your file: templates/shaper_spectrum/html/mod_menu/default.php using Helix3 file(s).
0
LB
Leon Beeloo
Accepted Answer
3 months ago #198279

Dear Paul,

Thank you for the advice, this fix indeed solved our problem for now.

The default.php of helix3 does correctly use the getter instead of trying to access properties directly. Shouldn't this correct usage of the getter be pushed in an update to shaper_spectrum? Otherwise, will this change be reverted the next update?

Can I be convinced that this is not only a temporary solution?

Best wishes, Twan kbite websupprt.

0