diff -u b/core/lib/Drupal/Component/Utility/ReadOnlyArrayIterator.php b/core/lib/Drupal/Component/Utility/ReadOnlyArrayIterator.php --- b/core/lib/Drupal/Component/Utility/ReadOnlyArrayIterator.php +++ b/core/lib/Drupal/Component/Utility/ReadOnlyArrayIterator.php @@ -14,7 +14,7 @@ */ public function offsetGet($index) { $value = parent::offsetGet($index); - if (is_array($value)) { + if (is_array($value) && !empty($value)) { $value = new ReadOnlyArrayObject($value); } return $value; @@ -25,7 +25,7 @@ */ public function current() { $value = parent::current(); - if (is_array($value)) { + if (is_array($value) && !empty($value)) { $value = new ReadOnlyArrayObject($value); } return $value; diff -u b/core/lib/Drupal/Component/Utility/ReadOnlyArrayObject.php b/core/lib/Drupal/Component/Utility/ReadOnlyArrayObject.php --- b/core/lib/Drupal/Component/Utility/ReadOnlyArrayObject.php +++ b/core/lib/Drupal/Component/Utility/ReadOnlyArrayObject.php @@ -14,7 +14,7 @@ */ public function offsetGet($index) { $value = parent::offsetGet($index); - if (is_array($value)) { + if (is_array($value) && !empty($value)) { $value = new ReadOnlyArrayObject($value); } return $value; diff -u b/core/lib/Drupal/Core/Template/TwigEnvironment.php b/core/lib/Drupal/Core/Template/TwigEnvironment.php --- b/core/lib/Drupal/Core/Template/TwigEnvironment.php +++ b/core/lib/Drupal/Core/Template/TwigEnvironment.php @@ -154,7 +154,7 @@ public function wrapContext(&$context) { if (is_array($context)) { foreach ($context as $key => $value) { - if (is_array($context[$key])) { + if (is_array($context[$key]) && !empty($context[$key])) { $context[$key] = new ReadOnlyArrayObject($context[$key]); } }