Re: Countable Type Hint
| From: | Josh Di Fabio | Date: | Thu, 17 Nov 2016 13:50:56 +0000 |
| Subject: | Re: Countable Type Hint | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-96950@lists.php.net to get a copy of this message | ||
On Thu, Nov 17, 2016 at 1:00 PM Levi Morrison <levim@php.net> wrote:
> On Thu, Nov 17, 2016 at 5:52 AM, Craig Duncan <php@duncanc.co.uk> 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?
> >
> > Thanks,
> > Craig
>
> It's definitely not doable with the name countable.
> Class/Trait/Interface names are case insensitive. This means
> countable already has meaning and it is unambiguously the
> interface.
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
What's the benefit of such an interface? Why not simply ask for `int
$count` in your param list instead?