cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2.3 - must be of the type array, null given - How to DeBug

Magento 2.3 - must be of the type array, null given - How to DeBug

Function :

 

    protected function mergeMetadataElement(array $bundleComponents, $name, array $data, $reverseMerge = false)
    {
        if (isset($bundleComponents[$name])) {
            $bundleComponents[$name] = $reverseMerge
                ? array_replace_recursive($data, $bundleComponents[$name])
                : array_replace_recursive($bundleComponents[$name], $data);
            return [$bundleComponents, true];
        } else {
            foreach ($bundleComponents as &$childData) {
                if (isset($childData['attributes']['class'])
                    && is_a($childData['attributes']['class'], \Magento\Ui\Component\Container::class, true)
                    && isset($childData['children']) && is_array($childData['children'])
                ) {
                    list($childData['children'], $isMerged) = $this->mergeMetadataElement(
                        $childData['children'],
                        $name,
                        $data,
                        $reverseMerge
                    );
                    if ($isMerged) {
                        return [$bundleComponents, true];
                    }
                }
            }
        }
        return [$bundleComponents, false];
    }

Argument 3 null given, it must be of the type array. How to start the debug?

4 REPLIES 4

Re: Magento 2.3 - must be of the type array, null given - How to DeBug

Hello @Aveeva 

 

It's a recursive function so you can change your code like below :

protected function mergeMetadataElement(array $bundleComponents, $name, array $data, $reverseMerge = false)
    {
        if (isset($bundleComponents[$name])) {
            $bundleComponents[$name] = $reverseMerge
                ? array_replace_recursive($data, $bundleComponents[$name])
                : array_replace_recursive($bundleComponents[$name], $data);
            return [$bundleComponents, true];
        } else {
            foreach ($bundleComponents as &$childData) {
                if (isset($childData['attributes']['class'])
                    && is_a($childData['attributes']['class'], \Magento\Ui\Component\Container::class, true)
                    && isset($childData['children']) && is_array($childData['children'])
                ) {
                   if(!isset($data)){
                         echo $name." <====== NAME";
                         exit;
                    }
                    list($childData['children'], $isMerged) = $this->mergeMetadataElement(
                        $childData['children'],
                        $name,
                        $data,
                        $reverseMerge
                    );
                    if ($isMerged) {
                        return [$bundleComponents, true];
                    }
                }
            }
        }
        return [$bundleComponents, false];
    }

It will throw you the name of element for which data is missing.

 

Hope it helps !

Problem Solved ? Click on 'Kudos' & Accept as Solution ! Smiley Happy

Re: Magento 2.3 - must be of the type array, null given - How to DeBug

@gaurav_harsh1  Where i can see the output of the following code,

 

if(!isset($data)){
    echo $name." <====== NAME";
    exit;
    }

Is upgrade and compile command need for this minor changes?

Re: Magento 2.3 - must be of the type array, null given - How to DeBug

@Aveeva 

Depends on the process you were doing to generate that error, do same process.

No need to run any command, changing in same file doesn't require it, just flush the cache and try.

Problem Solved ? Click on 'Kudos' & Accept as Solution ! Smiley Happy

Re: Magento 2.3 - must be of the type array, null given - How to DeBug

@gaurav_harsh1  After added your code, 

 

Click Add New product => 

 

Fatal error: Uncaught TypeError: Argument 3 passed to Magento\Framework\View\Element\UiComponentFactory::mergeMetadataElement() must be of the type array, null given, called in /var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php on line 391 and defined in /var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php:339 Stack trace: #0 /var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php(391): Magento\Framework\View\Element\UiComponentFactory->mergeMetadataElement(Array, 'configurableExi...', NULL, false) #1 /var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php(419): Magento\Framework\View\Element\UiComponentFactory->mergeMetadataItem(Array, Array, false) #2 /var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php(419): Magento\Framework\View\Element\UiComponentFactory->mergeMetadataItem(Array, Array, false) #3 /var/www/html/test/lib/internal/Magento/Fram in /var/www/html/test/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php on line 339 

 

There is no relevant information in system.log, debug.log, exception.log