Vox Populi(x) forum

Alexandria Book Library => Errori (Bugs) => Topic started by: Leauranger on 05 November 2026, 16:20:36

Title: Fatal error “Call to a member function authorise() on null” in Lends view
Post by: Leauranger on 05 November 2026, 16:20:36
Hello!
First thank you for this component.

Fatal error "Call to a member function authorise() on null" in Lends view for non-Super Users

Environment
lexandria Book Library (com_abook) 4.0.18

Description
In the administrator, opening the Lends manager (view=lends) with a user who is not a Super User, but whose group has access to the component's administration, causes a fatal error:

0 Call to a member function authorise() on null
administrator/components/com_abook/views/lends/view.html.php:74
AbookViewLends->addToolbar()

The page works correctly for Super Users.

Cause
In AbookViewLends::addToolbar(), the variable $user is used but never defined:

php
if ($canDo->get('core.admin') || $user->authorise('core.options', 'com_abook')){

For a Super User, core.admin is true, so the second condition is never evaluated. For any other user, $user->authorise() is called on null, which triggers the error.

Fix
Add the Factory import and define $user at the start of addToolbar():

diff
use Joomla\CMS\Helper\ContentHelper;
+use Joomla\CMS\Factory;
diff
protected function addToolbar()
{
$canDo  = ContentHelper::getActions('com_abook');
$toolbar = Toolbar::getInstance();
+ $user    = Factory::getApplication()->getIdentity();

Tested: the Lends manager now displays correctly for non-Super Users, with toolbar buttons shown according to their permissions.

It may be worth checking other views/*/view.html.php files for the same pattern.

Regards
Title: Re: Fatal error “Call to a member function authorise() on null” in Lends view
Post by: federica on 05 November 2026, 17:08:27
Hi Leauranger,
I fixed the bub, please install the new version.
Thanks
Title: Re: Fatal error “Call to a member function authorise() on null” in Lends view
Post by: Leauranger on 06 November 2026, 09:04:39
Thanks a lot for the quick fix! I installed 4.0.19 and the Lends view now works fine for non-Super Users. :)
Title: Re: Fatal error “Call to a member function authorise() on null” in Lends view
Post by: federica on 06 November 2026, 10:03:42
Thanks to you too for the feedback!