MemoryStorage fails with "Argument #1 ($array) must be of type array" error on calling function readMultiple()

Created on 6 December 2022, about 2 years ago
Updated 9 July 2023, over 1 year ago

Problem/Motivation

MemoryStorage fails with "Undefined array key" error, when we create a new object and call the function readMultiple().

The same approach for NullStorage works well without throwing an error.

Steps to reproduce

1. Run the code like this:

    $memoryStorage = new \Drupal\Core\Config\MemoryStorage('test');
    $values = $memoryStorage->readMultiple(['my_value']);

2. See the error:
TypeError: array_intersect_key(): Argument #1 ($array) must be of type array, null given in array_intersect_key() (line 58 of core/lib/Drupal/Core/Config/MemoryStorage.php).

3. Do the same with NullStorage:

    $memoryStorage = new \Drupal\Core\Config\NullStorage('test');
    $values = $memoryStorage->readMultiple(['my_value']);

and see that there is no error thrown.

Proposed resolution

Make a patch to check of the availability of the key and return NULL, instead of throwing the error.

Or use a workaround like this:

    $memoryStorage->write('__some_placeholder', []);

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Fixed

Version

10.1

Component
Configuration 

Last updated about 17 hours ago

Created by

🇦🇲Armenia murz Yerevan, Armenia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024