On 17/11/2016 13:52, Craig Duncan wrote:
Hi everybody
Following on from the recent rfc for *count()* (
https://wiki.php.net/rfc/counting_non_countables) and the one for *iterable*
(https://wiki.php.net/rfc/iterable) it would be useful if there was a
`countable` type hint:
function foo(countable $thing)
{
if (count($thing) > 0) {
# ...
}
}
However I think this it is much more useful when combined with *iterable*,
maybe something like (arraylike = iterable && countable)
function handle_records(arraylike $result)
{
if (count($result) === 0) {
handle_empty();
return;
}
foreach ($result as $value) {
handle_value($value);
}
}
Does anybody have any thoughts on this?
Should I bring *countable* to RFC?
Should I bring *arraylike* to RFC?
IMO if we add an arraylike-style hint it should include ArrayAccess as
well, and array_* functions should probably be fixed to work with
arraylike objects too, then it'd bring actual value.
Cheers
--
Jordi Boggiano
@seldaek - http://seld.be
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php