Issue Bug Closed

#104834Possible PHP warning with checkboxToggle

Xavier Perseguers 09/05/24, 13:32 updated 10/15/24, 09:06

Description

Under some circumstance, it’s possible that ‘items’ has been omitted in the TCA definition and this causes a PHP warning with that block:

        // Traversing the array of items
        $items = $this->data['parameterArray']['fieldConf']['config']['items'];

        $numberOfItems = count($items);
        if ($numberOfItems === 0) {
            $items[] = ['label' => ''];
            $numberOfItems = 1;
        }

Since there is already a proper check and fallback for emptiness, the null coalescing operator should be used as well in the first place:

$items = $this->data['parameterArray']['fieldConf']['config']['items'] ?? [];

Problem has been spotted in TYPO3 v11 already but code hasn’t changed in v12.

Reviews 2