Re: Proposal: Adding functions any(iterable $input, ?callable $cb = null, int $use_flags=0) and all(...)

From: Date: Sun, 30 Aug 2020 16:22:17 +0000
Subject: Re: Proposal: Adding functions any(iterable $input, ?callable $cb = null, int $use_flags=0) and all(...)
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-111726@lists.php.net to get a copy of this message
Hi Marco Pivetta, > Would it make sense, instead of having a third boolean parameter (causing two parameters to be > coupled together - already quite messy with existing array functions) for > any() and all() to just detect if > the given callback requires >1 parameter? > > That would make this much simpler. I find that to be inconsistent with how other internal functions accepting callbacks such as array_filter behave. It would also be unexpected if users or tooling wrap callbacks with other callbacks. Developers would also expect func_get_args() to work. ``` <?php function my_none(iterable $values, callable $predicate) { return all($values, fn(...$args) => $predicate(...$args)); } // PHP can't distinguish between these when given fn(...$args) // - would throw if passed 1 parameter my_none($values, fn($value, $key) => $value == true || $key == 'x'); // - would throw if passed 2 parameters (too many) my_none($values, 'is_string'); ``` Thanks, - Tyson

« previous php.internals (#111726) next »