Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118117 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 23221 invoked from network); 29 Jun 2022 00:02:43 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Jun 2022 00:02:43 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 615DC1804B3 for ; Tue, 28 Jun 2022 18:53:51 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f171.google.com (mail-yb1-f171.google.com [209.85.219.171]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 28 Jun 2022 18:53:50 -0700 (PDT) Received: by mail-yb1-f171.google.com with SMTP id v185so15819238ybe.8 for ; Tue, 28 Jun 2022 18:53:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=colopl.co.jp; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=0QRbdOvrFfcJUIrIsFGlRaRxO6Kn00+Bsx6ruGj6ah4=; b=R6mIP389lJHtB2M4WKux7wkJnU+xw304wHwJhS3AKS04NRqYUrE3I6UkVJnotm2gLb cI5OiTZ5z2Mkmpc81Tk/A7A8dBrjwTjE8SiLVxXfTeEn3iiT48binl+Y12sq8OAGc5Sh hl+91SlfvCyQHwcP+kr+TS0hYuOzl1BmswV/80JbfwR20//3F9ugtUZo6V+cx5CR6kj5 p+tf0Xd4TbrsPyqWkZTc5kYozv1g8QGbkBy34MDSfn2KLU9zRkd+HxMcTdcPlAbNCqET 6OkoEP6F5aNMgcVlqenAeoROms1DBEnofMo2X43urKjL2yuYEhjRBso+BpzHZLtCK22I v9/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=0QRbdOvrFfcJUIrIsFGlRaRxO6Kn00+Bsx6ruGj6ah4=; b=ux3U1XtClE3c3KG7uUukexPdEmfrgqDY57pMbHWcttWwXoAUeaW238aBajBOdqFhvQ cixneNT5ObjN0gbPNBOG56zc7C6CAK92wXIwopJ6S07DX0bbGHAX0RWN5r5x6BBgUuV6 k8aOcoT3h96knV9h9IS7kWJXSBA49dl+rt/jXSwjk9StKhs7u5rdlHV6FQiw2+f/nCOP 7cx5lfQ6QTsRQpiQKalK8xeJzgSQXwaP+u+3b40PqiRIye4znhjBkShkfRgDRpxrbYgc RWUH6s50n233j5rHU/a9KgU4BLroorU8RbigdMGRbvXlkiQnK6uVnLoD1AeNj0Lpizp7 izZg== X-Gm-Message-State: AJIora+uA1sB0yLyrSfAao0vxSZxbDREJVsKlAs11BtO/u6sWnPvYrdE jcdqwDzwG6+komugXnXnpv1hlqnAUpCpLB5UedOT X-Google-Smtp-Source: AGRyM1sBw8n3D3Hw/R8mAJs/NGtu0kAfRJalHybzW0y7rgFMmDZwbqocrDZWc+t8j1utgRNWh0x/KGmrq/xwNpAVdiU= X-Received: by 2002:a25:9387:0:b0:66c:91f4:92d8 with SMTP id a7-20020a259387000000b0066c91f492d8mr881588ybm.375.1656467630326; Tue, 28 Jun 2022 18:53:50 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 29 Jun 2022 10:53:39 +0900 Message-ID: To: Guilliam Xavier , internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000b0197705e28c6ccb" Subject: Re: [PHP-DEV] [RFC] [Under Discussion] Random Extension Improvement From: g-kudo@colopl.co.jp (Go Kudo) --000000000000b0197705e28c6ccb Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 2022=E5=B9=B46=E6=9C=8829=E6=97=A5(=E6=B0=B4) 0:39 Guilliam Xavier : > > 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 !=3D 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 --000000000000b0197705e28c6ccb--