mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-15 20:06:31 +00:00
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.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user