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:
-
change the property visibility from protected to public:
protected $params;
->
public $params;
I do not know if this change could have negative security implications.
-
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?