# [RFC] is_countable

- Thread: https://externals.io/message/101648
- Original archive: https://news-web.php.net/php.internals/101648
- Started by Gabriel Caruso on 2018-01-21T18:01:39+00:00
- Messages: 7
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #101648 — Gabriel Caruso — 2018-01-21T18:01:39+00:00

URL: https://externals.io/message/101648#101648

Hello, dear Internals.

First, thanks to Niklas Keller for giving me permission to write an *RFC*!
After that, I like to propose and discuss a new function for PHP 7.x
(current 7.3): is_countable.

*RFC*: https://wiki.php.net/rfc/is-countable.

I tried to describe everything there, but of course, let's discuss
everything that should be improved to get this functions merged into the
Core.

Thanks,



-- 
Gabriel Caruso

---

## #101649 — Levi Morrison — 2018-01-21T18:43:20+00:00

URL: https://externals.io/message/101648#101649 · In reply to: #101648

On Sun, Jan 21, 2018 at 11:01 AM, Gabriel Caruso
<carusogabriel34@gmail.com> wrote:
> Hello, dear Internals.
>
> First, thanks to Niklas Keller for giving me permission to write an *RFC*!
> After that, I like to propose and discuss a new function for PHP 7.x
> (current 7.3): is_countable.
>
> *RFC*: https://wiki.php.net/rfc/is-countable.
>
> I tried to describe everything there, but of course, let's discuss
> everything that should be improved to get this functions merged into the
> Core.

I added some comments on the implementation. I have no objection to
the RFC itself. It is small, useful, and relates to a core language
feature which in my opinion makes it a good candidate for our standard
library.

---

## #101650 — Craig Duncan — 2018-01-22T09:52:51+00:00

URL: https://externals.io/message/101648#101650 · In reply to: #101648

Hi Gabriel,

I proposed a similar function at the time of introducing the warning, but
it doesn't look like I got around to creating an RFC for it:
https://github.com/php/php-src/pull/2206/files

During this work we realised that objects don't have to implement the
'\Countable' interface to be successfully handled by 'count()',
internal/extension classes can implement a 'count_elements' handler and
ignore the interface.

I'd suggest that 'is_countable()' should be consistent with 'count()'.

Thanks,
Craig

---

## #101652 — johannes@schlueters.de — 2018-01-22T12:34:43+00:00

URL: https://externals.io/message/101648#101652 · In reply to: #101648

Hi,


> After that, I like to propose and discuss a new function for PHP 7.x
> (current 7.3): is_countable.
> 
> *RFC*: https://wiki.php.net/rfc/is-countable.

The primary place for this imo should be reflection. If there is high
demand we could also add a shortcut function like proposed (no strong
opinion on this either way from my side)

Of course I notice that the current reflection can't cover all the
cases you want to cover, so maybe it might be interesting to extend
reflection with something which works on all variables/zval and wraps
all the is_* functions.

johannes

---

## #101656 — Gabriel Caruso — 2018-01-22T16:45:55+00:00

URL: https://externals.io/message/101648#101656 · In reply to: #101652

Hi Johannes, thanks for your feedback!

Can I ask you to elaborate (or maybe share a link where can I study and
improve) more about the Reflection part?

Sorry if it’s sounds trivial, is because I’m new to internals 😄
Em seg, 22 de jan de 2018 às 10:34, Johannes Schlüter <
johannes@schlueters.de> escreveu:

> Hi,
>
> 
> > […]
>
> The primary place for this imo should be reflection. If there is high
> demand we could also add a shortcut function like proposed (no strong
> opinion on this either way from my side)
>
> Of course I notice that the current reflection can't cover all the
> cases you want to cover, so maybe it might be interesting to extend
> reflection with something which works on all variables/zval and wraps
> all the is_* functions.
>
> johannes
>
> --
Gabriel Caruso

---

## #101657 — Levi Morrison — 2018-01-22T17:15:59+00:00

URL: https://externals.io/message/101648#101657 · In reply to: #101652

On Mon, Jan 22, 2018 at 5:34 AM, Johannes Schlüter
<johannes@schlueters.de> wrote:
> Hi,
>
> 
> > […]
>
> The primary place for this imo should be reflection.

You did not provide any justification. As you do so keep in mind a lot
of code is going to look like:

    if (is_countable($arg)) {
        /* take a different code path, such as pre-allocating storage */
    }

This is not an easily reflectable thing because it's based on an
argument which may not even be an object type. Additionally we have a
well-established convention of `is_*` function for types specifically
known to the engine as is the case here.

---

## #101901 — Gabriel Caruso — 2018-02-22T18:31:27+00:00

URL: https://externals.io/message/101648#101901 · In reply to: #101648

>
> Hello, dear Internals.
>
> First, thanks to Niklas Keller for giving me permission to write an *RFC*!
> After that, I like to propose and discuss a new function for PHP 7.x
> (current 7.3): is_countable.
>
> *RFC*: https://wiki.php.net/rfc/is-countable.
>
> I tried to describe everything there, but of course, let's discuss
> everything that should be improved to get this functions merged into the
> Core.
>
> Thanks,
>
> --
> Gabriel Caruso
>


 Hello again, dear internals.

One month since the `is_countable` RFC had open.

We have add the support for `count_elements` (thanks @duncan3dc), so we can
use this function with internal classes as well.

There's only one open discussion from @morrisonlevi, but I do believe is
related to arginfo return type, which isn't used in the core yet, so I kept
without it.

Is something else we should do it, or I can open the voting next week
(26/02)?


-- 
Gabriel Caruso
