jolicode / automapper

:rocket: Very FAST :rocket: PHP AutoMapper with on the fly code generation
https://automapper.jolicode.com/
MIT License
154 stars 15 forks source link

Nullable array property does not work as epected #155

Closed lyrixx closed 5 months ago

lyrixx commented 5 months ago

My property

public ?array $descriptionList = null;

The generated code:

        if (null !== ($context['groups'] ?? array()) && array_intersect($context['groups'] ?? array(), array('crawl_url/clickhouse', 'crawl_url/read'))) {
            $values = array();
            foreach ($value->descriptionList as $key => $value_16) {
                $values[] = $value_16;
            }
            $result['descriptionList'] = $values;
        }

The error

In Symfony_Mapper_AppBundle_Api_Dto_Crawl_CrawlUrl_array.php line 142:

  [ErrorException]
  Warning: foreach() argument must be of type array|object, null given
lyrixx commented 5 months ago

Nevermind, There is a typo in my code:

    /** @var array<string> */
    public ?array $descriptionList = null;

Sorry for the noise !