Typed property must not be accessed before initialization Exception PHP Magento.

From PHP 7.4 Onwards, PHP introduced type hinting for all the properties. Based on the Type Hinting you need to assign proper value to match with that type.

Like, private int $size = 10;Here 10 is the default value for the $size variable.

Exception on Browser,

Typed property DataProvider::$loadedData must not be accessed before initialization, Exception in DataProvider.php class.

I have assigned array property like this,
private array $loadedData

I have changed it to,
private ?array $loadedData = null;

I have declared a null value for the loaded data and it’s working fine.

Working Example,

<?php declare(strict_types=1);

namespace Rbj\Blog\Model;

class DataProvider {
    private ?array $loadedData = null;

     * @return array
    public function getData(): array
        if (null !== $this->loadedData) {
            return $this->loadedData;

        // YOUR LOGIC TO LOAD DATA and Push it to $loadedData

        if (null === $this->loadedData) {
            $this->loadedData = [];

        return $this->loadedData;