Welcome! Log In Create A New Profile

Advanced

[PHP-DEV] [RFC] is_countable

Posted by Gabriel Caruso 
Gabriel Caruso
[PHP-DEV] [RFC] is_countable
January 21, 2018 07:10PM
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
Levi Morrison
Re: [PHP-DEV] [RFC] is_countable
January 21, 2018 07:50PM
On Sun, Jan 21, 2018 at 11:01 AM, Gabriel Caruso
<[email protected]> 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.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
Craig Duncan
Re: [PHP-DEV] [RFC] is_countable
January 22, 2018 11:00AM
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
Johannes Schlüter
Re: [PHP-DEV] [RFC] is_countable
January 22, 2018 01:40PM
Hi,

On So, 2018-01-21 at 18:01 +0000, Gabriel Caruso wrote:
> 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


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
Gabriel Caruso
Re: [PHP-DEV] [RFC] is_countable
January 22, 2018 05:50PM
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
Levi Morrison
Re: [PHP-DEV] [RFC] is_countable
January 22, 2018 06:20PM
On Mon, Jan 22, 2018 at 5:34 AM, Johannes Schlüter
<[email protected]> wrote:
> Hi,
>
> On So, 2018-01-21 at 18:01 +0000, Gabriel Caruso wrote:
>> 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.

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.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
Sorry, only registered users may post in this forum.

Click here to login