From b1b1e3c3a9dcb2cef511169f825f0b0125a4e60c Mon Sep 17 00:00:00 2001 From: javer Date: Sun, 15 Sep 2013 21:42:04 +0300 Subject: [PATCH] HHVM compatibility: array sometimes can be Traversable All checks on instance of Traversable prepended with is_object check. See facebook/hiphop-php#1034 for details. --- lib/Twig/Extension/Core.php | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 7eb7f9b..60fe193 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -348,7 +348,7 @@ function twig_random(Twig_Environment $env, $values = null) return $values < 0 ? mt_rand($values, 0) : mt_rand(0, $values); } - if ($values instanceof Traversable) { + if (is_object($values) && $values instanceof Traversable) { $values = iterator_to_array($values); } elseif (is_string($values)) { if ('' === $values) { @@ -620,7 +620,7 @@ function twig_array_merge($arr1, $arr2) */ function twig_slice(Twig_Environment $env, $item, $start, $length = null, $preserveKeys = false) { - if ($item instanceof Traversable) { + if (is_object($item) && $item instanceof Traversable) { $item = iterator_to_array($item, false); } @@ -687,7 +687,7 @@ function twig_last(Twig_Environment $env, $item) */ function twig_join_filter($value, $glue = '') { - if ($value instanceof Traversable) { + if (is_object($value) && $value instanceof Traversable) { $value = iterator_to_array($value, false); } @@ -829,7 +829,7 @@ function twig_in_filter($value, $compare) } return false !== strpos($compare, (string) $value); - } elseif ($compare instanceof Traversable) { + } elseif (is_object($compare) && $compare instanceof Traversable) { return in_array($value, iterator_to_array($compare, false), is_object($value)); } @@ -1335,7 +1335,7 @@ function twig_constant($constant, $object = null) */ function twig_array_batch($items, $size, $fill = null) { - if ($items instanceof Traversable) { + if (is_object($items) && $items instanceof Traversable) { $items = iterator_to_array($items, false); } -- 1.7.2.5