/**
* Sorts an array.
- *
+ *
* @param array $array An array
*/
function twig_sort_filter($array)
* <pre>
* {% if foo.attribute is sameas(false) %}
* the foo attribute really is the ``false`` PHP value
- * {% endif %}
+ * {% endif %}
* </pre>
*
* @param mixed $value A PHP variable
*/
function twig_test_empty($value)
{
+ if ($value instanceof Countable) {
+ return 0 == count($value);
+ }
return false === $value || (empty($value) && '0' != $value);
}
{{ array is empty ? 'ok' : 'ko' }}
{{ zero is empty ? 'ok' : 'ko' }}
{{ string is empty ? 'ok' : 'ko' }}
+{{ countable_empty is empty ? 'ok' : 'ko' }}
+{{ countable_not_empty is empty ? 'ok' : 'ko' }}
--DATA--
-return array('foo' => '', 'bar' => null, 'foobar' => false, 'array' => array(), 'zero' => 0, 'string' => '0');
+
+class CountableStub implements Countable
+{
+ private $items;
+
+ public function __construct(array $items)
+ {
+ $this->items = $items;
+ }
+
+ public function count()
+ {
+ return count($this->items);
+ }
+}
+return array('foo' => '', 'bar' => null, 'foobar' => false, 'array' => array(), 'zero' => 0, 'string' => '0', 'countable_empty' => new CountableStub(array()), 'countable_not_empty' => new CountableStub(array(1, 2)));
--EXPECT--
ok
ok
ok
ok
ko
+ko
+ok
ko
\ No newline at end of file