Issue Bug Closed

#107051PHP 8.1+ deprecation warning: "Automatic conversion of false to array is deprecated" in CategoryCollection::load() when content elements reference deleted categories

David Retzer 07/07/25, 09:51 updated 12/02/25, 14:38

Description

*Problem:*
When content elements with category menus reference categories that have been deleted (deleted=1), PHP 8.1+ throws deprecation warnings:

PHP Warning: Undefined array key "uid" in /var/www/html/vendor/typo3/cms-core/Classes/Collection/AbstractRecordCollection.php line 433 
PHP Runtime Deprecation Notice: Automatic conversion of false to array is deprecated in /var/www/html/vendor/typo3/cms-frontend/Classes/Category/Collection/CategoryCollection.php line 91

*Root Cause:*
In CategoryCollection::load(), the method calls $queryBuilder->executeQuery()->fetchAssociative() which returns false when no category is found (e.g., deleted categories). The code then treats this false value as an array, causing the deprecation warning.

Steps to Reproduce:
  1. Create a content element with category menu
  2. Assign categories to the content element
  3. Delete one of the referenced categories (set deleted=1)
  4. Access the page with the content element
  5. Check PHP error log for deprecation warnings

*Expected Behavior:*
No PHP warnings should occur. The system should handle deleted categories gracefully.

*Actual Behavior:*
PHP 8.1+ deprecation warnings appear in logs.

*Proposed Fix:*
In CategoryCollection::load(), check if fetchAssociative() returns false and return early with an empty array:

// Handle case where fetchAssociative() returns false (no record found)
if ($collectionRecord === false) {
    return [];
}

And update the method’s return type annotation to @return array|CategoryCollection to reflect that it can return either an array or a CategoryCollection instance.

Impact :
  • Affects all installations with PHP 8.1+ and content elements referencing deleted categories
  • Warnings pollute error logs
  • No frontend functionality is broken, but logs become cluttered

Reviews 4

History 711

  1. Garvin Hicking commented and changed status New Needs Feedback <span data-processor="relativetime" data-value="2025-07-07T10:05:32+00:00" > 07/07/25, 10:05 </span>

    Hi!

    Which TYPO3 version do you use exactly? This bug should’ve been fixed a year ago if I read correctly:

    https://review.typo3.org/c/Packages/TYPO3.CMS/+/84624 – this is included in TYPO3 12.4.17+

  2. David Retzer commented <span data-processor="relativetime" data-value="2025-07-07T10:38:29+00:00" > 07/07/25, 10:38 </span>

    Garvin Hicking wrote in #note-2:
    > Hi!
    >
    > Which TYPO3 version do you use exactly? This bug should’ve been fixed a year ago if I read correctly:
    >
    > https://review.typo3.org/c/Packages/TYPO3.CMS/+/84624 – this is included in TYPO3 12.4.17+

    Hi Garvin,

    we are using TYPO3 v12.4.33. You’re absolutely right that this was fixed in TYPO3 Core 12.4.17+ for the Core CategoryCollection class.

    However, our issue is specifically with the Frontend CategoryCollection class:
    • File: `cms-frontend/Classes/Category/Collection/CategoryCollection.php`
    • Class: `TYPO3\CMS\Frontend\Category\Collection\CategoryCollection`

    The Frontend CategoryCollection’s `load()` method doesn’t include the fix that was applied to the Core version. It still has the original problematic code that causes the PHP 8.1+ deprecation warnings.

    So while the Core issue is fixed, the Frontend-specific implementation still needs the same fix applied.

    Best regards
    David

  3. Garvin Hicking commented <span data-processor="relativetime" data-value="2025-07-07T11:00:12+00:00" > 07/07/25, 11:00 </span>

    Understood! Are you interested in trying to provide a patch so this fix can be attributed to you? I could offer guidance in this case.

    Otherwise, I can apply a fix for you. We should go the same route as the core fix though, so not return an empty array, but an empty CategoryCollection, so that type hints and further proccessing can kick in.

    Thanks a lot!

  4. Gerrit Code Review pushed patch set 1 for main to change 90031 status Needs Feedback Under Review <span data-processor="relativetime" data-value="2025-07-09T10:03:56+00:00" > 07/09/25, 10:03 </span>

  5. David Retzer commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2025-07-09T17:45:08+00:00" > 07/09/25, 17:45 </span>

    Applied in changeset commit:5972e5d0d73a33098e3d2e9b230eca4c94abae5a.

  6. Gerrit Code Review pushed patch set 1 for 12.4 to change 90258 status Resolved Under Review <span data-processor="relativetime" data-value="2025-08-05T10:51:24+00:00" > 08/05/25, 10:51 </span>

  7. David Retzer commented and changed status Under Review Resolved <span data-processor="relativetime" data-value="2025-08-05T12:55:09+00:00" > 08/05/25, 12:55 </span>

    Applied in changeset commit:34578cf7747c1ef36b2c77ee4c24dc93752eca34.