PHP Fatal error: Uncaught Error: Cannot unset string offsets when trying to upload any file to media library

I have the same issue on only one of the three wordpress sites managed by a multisite wordpress.
I am not experienced with WordPress either, but I have managed to get uploads working by replacing

if ( empty( $directory_cache ) ) {
    return;
}

by

if ( empty( $directory_cache ) || !is_array($directory_cache) ) {
    return;
}

at line 8368 in wp-includes/functions.php

I have not yet encountered any inconvenience with this change but it still might have some unexpected implications.