Re: [PHP-DEV] [RFC] is_countable
On Mon, Jan 22, 2018 at 5:34 AM, Johannes Schlüter wrote: > Hi, > > On So, 2018-01-21 at 18:01 +, 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
Re: [PHP-DEV] [RFC] is_countable
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 < johan...@schlueters.de> escreveu: > Hi, > > On So, 2018-01-21 at 18:01 +, 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 > > -- Gabriel Caruso
Re: [PHP-DEV] [RFC] is_countable
Hi, On So, 2018-01-21 at 18:01 +, 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
Re: [PHP-DEV] [RFC] is_countable
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
Re: [PHP-DEV] [RFC] is_countable
On Sun, Jan 21, 2018 at 11:01 AM, Gabriel Caruso 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
[PHP-DEV] [RFC] is_countable
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