2022年6月29日(水) 0:39 Guilliam Xavier <guilliam.xav...@gmail.com>:
> > Hi Internals. > > > > Random Extension 5.x has been accepted by a vote of 20(+1)/0. (I made a > > mistake in timing the closing of the vote and thus received one more > vote) > > Therefore, voting on the Random Extension Improvement RFC will begin on > > 2022-07-02 as scheduled. > > > > Please check the RFC. This is the last chance to improve the > implementation. > > > > https://wiki.php.net/rfc/random_extension_improvement > > Hi, > > I just realized a little thing: in the array_rand() example, for > $beforeSingle, it would probably be "more realistic" to omit `, 1` > (which is already the default for $num). > > Note: for `Randomizer::pickArrayKeys(array $array, int $num): array`, > it makes sense that $num does *not* have a default value (1 would be > "weird" because the method always returns a *list of keys*, and > count($array) [via null] would be "useless" because keys are returned > *in their original order* [so it would make the method equivalent to > array_keys($array) by default]), > and that's probably a good thing (it forces to update the call by > adding an explicit `, 1` argument and reminds to add a `[0]` or > similar on the returned value). > > An alternative design would be `Randomizer::pickArrayKey(array > $array): int|string`, but migrating existing uses with $num != 1 would > be harder, so probably not better. > > Regards, > > -- > Guilliam Xavier > This is certainly a complicated issue. I proposed the signature `Randomizer::arrayPickKeys(array $array, int $num): array` because it can be solved with the current PHP sugar syntax and the default value of $num is 1 despite the name "arrayPickKeys". However, this is a bit tricky and may not be user-friendly for the average user. So, how about adding two methods, `Randomizer::arrayPickKey(array $array): int|string` and `Randomizer::arrayPickKeys(array $array, int $num): array`? This may seem redundant, but it may avoid user confusion. Regards Go Kudo