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
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.
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
Hi,
After that, I like to propose and discuss a new function for PHP 7.x
(current 7.3): 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
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,
After that, I like to propose and discuss a new function for PHP 7.x
(current 7.3): 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
On Mon, Jan 22, 2018 at 5:34 AM, Johannes Schlüter
johannes@schlueters.de wrote:
Hi,
After that, I like to propose and discuss a new function for PHP 7.x
(current 7.3): 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.
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