Support

Admin Tools

#40007 Warning: Undefined array key 0

Posted in ‘Admin Tools for Joomla! 4 & 5’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Environment Information

Joomla! version
Joomla! 5.0.1 Stable [ Kubores
PHP version
8.2.13 (Also tried 8.1.26)
Admin Tools version
Admin Tools Pro

Latest post by ml09616 on Tuesday, 19 December 2023 07:49 CST

ml09616

I am getting these warnings which seem to be related to a line(s) 311 & 321 in the AdminTools php file: public_html/plugins/system/admintools/src/Extension/AdminTools.php

Warning: Undefined array key 0 in /home/garrod5/public_html/plugins/system/admintools/src/Extension/AdminTools.php on line 321
Warning: Undefined array key 1 in /home/garrod5/public_html/plugins/system/admintools/src/Extension/AdminTools.php on line 321
Warning: Undefined array key 0 in /home/garrod5/public_html/plugins/system/admintools/src/Extension/AdminTools.php on line 311
Warning: Undefined array key 1 in /home/garrod5/public_html/plugins/system/admintools/src/Extension/AdminTools.php on line 311
Warning: Undefined array key 0 in /home/garrod5/public_html/plugins/system/admintools/src/Extension/AdminTools.php on line 321
Warning: Undefined array key 1 in /home/garrod5/public_html/plugins/system/admintools/src/Extension/AdminTools.php on line 321

They appear when I am in AdminTools Configure WAF, and also when I am in other components

I can disable ALL warning / error messages in Global Configuration, but not sure if this is a good thing to do.

Can you please give me some guidance (my PHP skills ar somewhat lacking!)

I have done a search but can't make much headway.

regards

Mike

 

nicholas
Akeeba Staff
Manager

Third party code (NOT Admin Tools) is calling the onUserAfterSave Joomla event with no arguments, or the wrong argument count. In other words, this is a problem in third party code, not ours.

I can explain this with code, since I wrote Joomla's concrete events code myself a couple of years ago.

The \Joomla\CMS\Event\CoreEventAware trait in the file libraries/src/Event/CoreEventAware.php shows the mapping between event handlers and concrete event classes. The onUserAfterSave is mapped to the \Joomla\CMS\Event\User\AfterSaveEvent class which lives in the libraries/src/Event/User/AfterSaveEvent.php file.

Towards the top of that file you see this:

protected $legacyArgumentsOrder = ['subject', 'isNew', 'savingResult', 'errorMessage'];

This gives you the argument count, their order, and their (canonical) names. As you can see, we have four arguments.

As you can see in our code (the \Akeeba\Plugin\System\AdminTools\Extension\AdminTools::onUserAfterSave method in the system/admintools/src/Extension/AdminTools.php file) we unwrap these arguments with this code:

[$user, $isnew, $success, $msg] = array_values($event->getArguments());

This unwrapping trick is something I invented during the Joomla! 5 beta period and is now also used in core Joomla! code thanks to the core maintainer Fedir Zinchuk who's converting all of Joomla's core code into concrete events. That is to say, unwrapping event arguments using PHP list unwrapping against array_values($event->getArguments()) is the canonical, official way of doing it.

Back to our code. As you can see, we unwrap four arguments in the same order and with the same meaning as what you saw in the  \Joomla\CMS\Event\User\AfterSaveEvent class. Note that the subject of the user events is always a user object, that's why I am using a variable named $user; it has no functional role, but giving the variable name a semantic meaning makes it far less likely that I'll get confused and introduce bugs when consuming it.

Now let's look at the PHP warnings again. You get warnings about key 0 and key 1 in the list unwrapping. These are the first two mandatory arguments, subject and isNew. This means that something triggered Joomla's onUserAfterSave event without sending the user object and whether this is a new user. This is possible if someone triggered the event using the legacy code which is still supported but deprecated in Joomla! 5 (and which will cause a PHP fatal error in Joomla! 6). So, this is definitely a third party plugin messing up.

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

ml09616

Thanks Nicolas for your reply. I will close this ticket after posting this reply.

That has given me some information to chase this down...  I will look at the other 3rd party plugins to isolate which is causing the issue!

You are a legend!   thanks again for your help, and the great software!

rgds

Mike

Support Information

Working hours: We are open Monday to Friday, 9am to 7pm Cyprus timezone (EET / EEST). Support is provided by the same developers writing the software, all of which live in Europe. You can still file tickets outside of our working hours, but we cannot respond to them until we're back at the office.

Support policy: We would like to kindly inform you that when using our support you have already agreed to the Support Policy which is part of our Terms of Service. Thank you for your understanding and for helping us help you!