Cannot access protected property Joomla\CMS\Menu\MenuItem::$params - Forum | JoomShaper
Solved Templates

Cannot access protected property Joomla\CMS\Menu\MenuItem::$params

Asked by Leon Beeloo 1 year ago Last activity 1 year 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?

Accepted answer

Marked as the solution
Paul Frankowski Senior Staff

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.

3 more replies

Toufiq Senior Staff

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)

Leon Beeloo Asked this

see below

Toufiq Senior Staff

Please check the screenshot.

Leon Beeloo Asked this
Toufiq Senior Staff

Now your secret links don't work.

Leon Beeloo Asked this
Paul Frankowski Senior Staff
1 year ago · edited

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).
Leon Beeloo Asked this

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.

Log in to reply.