Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118157 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 22565 invoked from network); 1 Jul 2022 21:09:57 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 1 Jul 2022 21:09:57 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3124D1804BD for ; Fri, 1 Jul 2022 16:01:49 -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,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (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 ; Fri, 1 Jul 2022 16:01:48 -0700 (PDT) Received: by mail-ej1-f46.google.com with SMTP id g26so6485241ejb.5 for ; Fri, 01 Jul 2022 16:01:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=sfU6DOse9KyqJspWaN/nYLJluxm8xVqUyNV862qnqws=; b=py07TMBJ0bPChx3gVV6Js63rC1Mu5KTeV+4VWztQZbMcEjb76d6MactDUUeq0M3qsQ gyGofOcfbiDr2JYHnitUxWzq8z9ak5GsbSaoITNnfnZXMUtpssN1E6Wd2fPV657wHVT+ 3+4BaLK2KHMq16qc2h8neGb28tqxbt5HPFfcivLmNIvF4FyttvXY5hOgnLcu4zSjSFBj ly2/dAihq/7QlneevSaUv9PiPGVza6e3vI+oByi2wiUCwbNxOqpGN0UQ65iZrBFLXeD3 2eQhUrAcqYPGN6hpbPbwVcABMzGL/jwZ1x5+iPyf7EJ1Tp/STZ/+OymHtA/tevIMfHgw 0rug== 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=sfU6DOse9KyqJspWaN/nYLJluxm8xVqUyNV862qnqws=; b=Wu+ZC9J/4VBDXmK8yZ9qhBdR5M4BZe5rlUyhSnbnFOG07uAsEh4f2w3+kPKzErKPNt 3NKdoMvp41leDkQl3Slt+3nDnoa+JVuUZ2e1Y5rMSd1Psv+qYNBi4ozfKtyMQL/lhd5k sbhiIDCxzGGkR4SjiDET68RAxpf2Gbdx06jPgeDtwdjlGDboGnSsd8OfVbHgkHErcLeJ d5N/e5l0k0I/Th/Dk9m9BxuZ8ZhyTFEzUOOTsgb43f2wFlsctcsbgZjQsQMhl1OynZCV 6PwWTeXlcTZ/uA3XD+cz8vFMk5yxwoeKnIeZRJkdjS3fMtipMyd+OPvyoi31/18SqDcO nRXQ== X-Gm-Message-State: AJIora98MqfqFTqQe4M4U+StRk/Cptjc+PXrCDbv4Zv2l24f5jjbXYQj cnyUODSl7fAlp2B3qQ4igHaOJS11qlPuyYsEWWg= X-Google-Smtp-Source: AGRyM1t4fWHcisZkNrUzdxJK4y7FokDfvKnHFUUTmH64a9VqvgN+6BwE7OPPrcKgOBhk7YGbsam1YcyeqAr1dRmW8vM= X-Received: by 2002:a17:906:c354:b0:726:3b55:7045 with SMTP id ci20-20020a170906c35400b007263b557045mr16302297ejb.723.1656716507146; Fri, 01 Jul 2022 16:01:47 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 2 Jul 2022 08:01:35 +0900 Message-ID: To: Guilliam Xavier , =?UTF-8?Q?Tim_D=C3=BCsterhus?= , PHP internals Content-Type: multipart/alternative; boundary="000000000000e6ed0505e2c65eca" Subject: Re: [PHP-DEV] [RFC] [Under Discussion] Random Extension Improvement From: zeriyoshi@gmail.com (Go Kudo) --000000000000e6ed0505e2c65eca 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) 17:40 Guilliam Xavier : > >> > https://wiki.php.net/rfc/random_extension_improvement > >> > >> 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 wou= ld > >> be harder, so probably not better. > > > > 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. > > Sorry if I wasn't clear: I just suggested to make this little change > in the example: > > ```diff > -$beforeSingle =3D array_rand(['foo' =3D> 'foo', 'bar' =3D> 'bar', 'baz' = =3D> > 'baz'], 1); // (string) foo > +$beforeSingle =3D array_rand(['foo' =3D> 'foo', 'bar' =3D> 'bar', 'baz' = =3D> > 'baz']); // (string) foo > ``` > > to make it more "realistic". > > As concerns the rest (about pickArrayKeys): sorry for the digression, > I was just "thinking out loud", I *don't* want any change there > (first, it makes sense that pickArrayKeys has `int $num` *without* a > default value [even if array_rand has 1]; second, "pickArrayKey" [if > really wanted] is trivial to implement in userland as a wrapper around > pickArrayKeys [but the opposite would not be so], and I don't think > that adding *both* methods to Randomizer is desirable either [better > keep it simple/minimal]). > > Regards, > > -- > Guilliam Xavier > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > Hi Thank you. That feels true. I will try to keep the RFC as it currently stands. Sorry for the delay in replying. I was a little held up with personal business. I will delay the start of voting by one day. Best regards Go Kudo --000000000000e6ed0505e2c65eca--