PHP 8 fatal: undefined $categoryOptions in Falang filter

  • Posts: 39
  • Thank you received: 6
  • Hikashop Business
4 hours 34 minutes ago #373307

-- HikaShop version -- : 6.6.0_2026-09-08_05-07-16
-- Joomla version -- : 6.1.3
-- PHP version -- : 8.5.9

Hello,

I would like to report a small issue in the Falang content element file
shipped with HikaShop.

File:
back/falang/translationHikashop_product_categoryFilter.php
(installed to administrator/components/com_falang/contentelements/)
Version: 6.6.0, package downloaded 2026-09-08

In _createfilterHTML(), the variable $categoryOptions is only assigned
inside the foreach loop:

$category_list = $db->loadObjectList();
foreach($category_list as $k=>$category){
$categoryOptions[$k] = \Joomla\CMS\HTML\HTMLHelper::_('select.option', ...);
}
...
$options = array_merge($allCategoryOptions, $categoryOptions);

It is never initialized before the loop. If the query returns no rows,
$categoryOptions stays undefined and is passed to array_merge(). On PHP 8
this is a fatal error:

array_merge(): Argument #2 ($arrays) must be of type array, null given

The query only returns rows when at least one product is linked to a
category, so the empty result happens when the shop has no products yet,
or when no product is assigned to any category.

Suggested fix, one line before the loop:

$categoryOptions = array();

How this was found, and what it is not:

I updated Falang Pro from 6.8 to 6.9 and asked Claude (an AI assistant) to
compare the affected files so I would know which of my manual patches had
to be reapplied. During that review it noticed this uninitialized variable
and recommended that I report it to you. I then downloaded the current
HikaShop Business package on 2026-09-08 and confirmed the code is still
unchanged in 6.6.0.

So this is a code review remark, not a reproduced bug. I have not seen the
error on my own site: all of my products are assigned to categories, so
the query is never empty here. Please weigh it accordingly.

My environment:
Joomla 6.1 / PHP 8 / HikaShop Business 6.6.0 / Falang Pro 6.9

By the way, thank you for switching this file from JFactory / JHtml / JText
to the namespaced classes in 6.6.0. I had been patching it by hand for
Joomla 6, and that is no longer necessary.

Best regards,

Please Log in or Create an account to join the conversation.

  • Posts: 86100
  • Thank you received: 14202
  • MODERATOR
30 minutes ago #373309

Hello,

You are right, and thank you for the precise report. $categoryOptions is only created inside the loop, so a shop where no product belongs to a category leaves it undefined, and PHP 8 stops on the array_merge with exactly the message you quote.

It is fixed for the next release with the line you suggested:

		$allCategoryOptions = array();
		$categoryOptions = array();

Looking at the file we also corrected the filter itself: choosing a category which no longer holds any product produced c.product_id IN(), which the database refuses. It now matches nothing instead.

Glad the namespaced classes save you a patch, that change was made for the Joomla 6 support of 6.6.0.

You can download the install package of HikaShop on our website and install it on yours in order to get the patchs automatically.

The following user(s) said Thank You: Alouette00

Please Log in or Create an account to join the conversation.

Time to create page: 0.053 seconds
Powered by Kunena Forum