respect-validation/docs/rules/IterableVal.md
Henrique Moody 210aa4ac01
Recreate "IterableType" rule
The difference with this rule is that it matches the behavior of
`is_iterable()`, which is different from `IterableVal` that also allows
instances of `stdClass.`

This is a necessary change because PHP will trigger an error when trying
to pass any object to anything typed as `iterable`

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-03-02 13:20:13 +01:00

1.1 KiB

IterableVal

  • IterableVal()

Validates whether the input is an iterable value, in other words, if you can iterate over it with the foreach language construct.

v::iterableVal()->validate([]); // true
v::iterableVal()->validate(new ArrayObject()); // true
v::iterableVal()->validate(new stdClass()); // true
v::iterableVal()->validate('string'); // false

Note

This rule doesn't behave as PHP's [is_iterable() function because it considers that you can iterate over any object.

Categorization

  • Types

Changelog

Version Description
3.0.0 Renamed from IterableType to IterableVal
1.0.8 Renamed from Iterable to IterableType
1.0.0 Created as Iterable

See also: