/* used internally */
function twig_in_filter($value, $compare)
{
+ $strict = is_object($value);
+
if (is_array($compare)) {
- return in_array($value, $compare);
+ return in_array($value, $compare, $strict);
} elseif (is_string($compare)) {
if (!strlen((string) $value)) {
return empty($compare);
return false !== strpos($compare, (string) $value);
} elseif (is_object($compare) && $compare instanceof Traversable) {
- return in_array($value, iterator_to_array($compare, false));
+ return in_array($value, iterator_to_array($compare, false), $strict);
}
return false;
--- /dev/null
+--TEST--
+Twig supports the in operator when using objects
+--TEMPLATE--
+{% if object in object_list %}
+TRUE
+{% endif %}
+--DATA--
+$foo = new Foo();
+$foo1 = new Foo();
+
+$foo->position = $foo1;
+$foo1->position = $foo;
+
+return array(
+ 'object' => $foo,
+ 'object_list' => array($foo1, $foo),
+);
+--EXPECT--
+TRUE