function twig_in_filter($value, $compare)
{
if (is_array($compare)) {
- return in_array($value, $compare, is_object($value));
+ return in_array($value, $compare, true);
} elseif (is_string($compare)) {
- if (!strlen($value)) {
- return empty($compare);
+ if (!is_string($value)) {
+ return false;
}
- return false !== strpos($compare, (string) $value);
+ return '' === $value || false !== strpos($compare, $value);
} elseif ($compare instanceof Traversable) {
- return in_array($value, iterator_to_array($compare, false), is_object($value));
+ return in_array($value, iterator_to_array($compare, false), true);
}
return false;
{% if '0' in '0' %}
TRUE
{% endif %}
+{{ false in [0, 1] ? 'TRUE' : 'FALSE' }}
+{{ true in [0, 1] ? 'TRUE' : 'FALSE' }}
+{{ '0' in [0, 1] ? 'TRUE' : 'FALSE' }}
+{{ '' in [0, 1] ? 'TRUE' : 'FALSE' }}
+{{ 0 in ['', 1] ? 'TRUE' : 'FALSE' }}
+{{ '' in 'foo' ? 'TRUE' : 'FALSE' }}
+{{ 0 in 'foo' ? 'TRUE' : 'FALSE' }}
+{{ false in 'foo' ? 'TRUE' : 'FALSE' }}
+{{ true in '100' ? 'TRUE' : 'FALSE' }}
+{{ [] in 'Array' ? 'TRUE' : 'FALSE' }}
+{{ [] in [true, false] ? 'TRUE' : 'FALSE' }}
+{{ [] in [true, ''] ? 'TRUE' : 'FALSE' }}
+{{ [] in [true, []] ? 'TRUE' : 'FALSE' }}
+{{ dir_object in 'foo'~dir_name ? 'TRUE' : 'FALSE' }}
+{{ 5 in 125 ? 'TRUE' : 'FALSE' }}
--DATA--
-return array('bar' => 'bar', 'foo' => array('bar' => 'bar'))
+return array('bar' => 'bar', 'foo' => array('bar' => 'bar'), 'dir_name' => dirname(__FILE__), 'dir_object' => new SplFileInfo(dirname(__FILE__)))
--EXPECT--
TRUE
TRUE
TRUE
TRUE
TRUE
+FALSE
+FALSE
+FALSE
+FALSE
+FALSE
TRUE
+FALSE
+FALSE
+FALSE
+FALSE
+FALSE
+FALSE
+TRUE
+FALSE
+FALSE