Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125816 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id A7F601A00BD for ; Sun, 20 Oct 2024 23:17:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1729466364; bh=GemvFYKkW1U0abGwAC6tDuu0P9N+VKWYuRN5AZOfTJc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=enQAxs0njtpam4iWW900HR+uWYZ4A9XtmpwQU8j1BjRP9xYUSSF+0789hSETX1I67 neJ6cI01QKVZwdHx/mwKTfEE/Ous5rUp7hL1WfzHHCvmANvgoCK2ii9gP4mb5wo4+s B1SfbGaxBY8WDrhuHgPvba5oc9D3nG2VicKB6JOEfYsxmC1YxMl/xjbbIZCopYL/Va ub2Cki4pcujcHD7ISqs4e5A3Qw5jSZOYSmQgDVez45Ezja1wpOR5jvSEpLCwbVMP1r UW3CSwvabhMDNgCDhwUuw9t2AmK6QkwTFOKeESpLjYYrHB63OvK/dbHl0KVy3YbJtE 7YFxJKsV98xQg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 09D2E18006A for ; Sun, 20 Oct 2024 23:19:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 20 Oct 2024 23:19:20 +0000 (UTC) Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5c903f5bd0eso7029759a12.3 for ; Sun, 20 Oct 2024 16:16:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729466216; x=1730071016; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=3sQ4sNIZOk+W/XOiLAXx0S/fAxcF1DBaco0yIywfS+A=; b=c7PfWxDLUKM56g9wdpLaV4QQxQrj3GbwgEVGwZeX+zZOaMVd9YhRS4CCqudFSD0Af6 enRxT34Rq6CHxBzeOnFn08gTn5njltlvz75VjNNmDmpx6HXcD220xkTNaRpDgPavoXmE krmsLHpzAtHymGpMVI6oD4JMvCBpR4mYkjn3MRcpIalfq5MUkZ5FoAZLe3LNIwS/iv4n 0Qdjg/Meq61ySNCx5plOuLnEK9z6p0zfijNra4wX6lN/YwRcfxygNKkvK7fSBDJfQ6Mb Gqe7/4XVmrgo/8QJcz9b6/PApK3ORLUVYQadpqm30E5Uhx+okV7dUJFVwNi5KBrd0Faz MhKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729466216; x=1730071016; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3sQ4sNIZOk+W/XOiLAXx0S/fAxcF1DBaco0yIywfS+A=; b=Vitr0DgfpJlp4cZsBRaVk1yD3X3RK6v3V2IAgZnQs1P+3PRO6dtsWKUF91b3EA2bvM mz8c3LrA8VYmgSRoWnIkSWxTWEm1+jX6+T1ml3TytWkUSrN87TT17WlcEiNXKp+x2WKs jB6puxo+UsQU8TLgGPaoC9KqE4I3ZsXKR75dPYLPXfGxH4ZGXLRGnqFtqHrYebFuRXGu XdZZnUWe1QFmDi/SPtXgLdBeAdVBo901wGqlFYNVFnPwN4/C34gV/KUibg8kTF8jVnSS UEoC4zyQtQ8pXg2M1b9AYW0odtVyMcQurn8Leja9PNNnMVbyVzy2+lZVKfg+c3LOuTOt 7GIg== X-Gm-Message-State: AOJu0YzcC95THpdXeuVWFheYRBKBWedEW2stoGkhv+GPlSOwG1q/kaNc awtZPRMVl/ohWGUYTFAGyjOPYYcxd8j9xhaFU8JBnnL7FsuraY4hfmPq8bKSlJDpzz+fzLlhqgL 2JjR7pGmYvVeB0EUuZQC0Ei8P9B5wecjo X-Google-Smtp-Source: AGHT+IE4oAz/E6ea5DC0UDp4s5kYv8ENJ76U3bohJvo71Id2/sA5W1EqZCnwRRpdkOTB9YKG96IGr1c7Tm4+4WpOcVo= X-Received: by 2002:a05:6402:354f:b0:5c8:a0fd:63d6 with SMTP id 4fb4d7f45d1cf-5ca0ae83e6emr7946725a12.20.1729466215624; Sun, 20 Oct 2024 16:16:55 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 21 Oct 2024 09:16:44 +1000 Message-ID: Subject: Re: [PHP-DEV] [RFC] Change behaviour of array sort functions to return a copy of the sorted array To: "Gina P. Banyard" Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000006efbb70624f0bbb3" From: mickmackusa@gmail.com (mickmackusa) --0000000000006efbb70624f0bbb3 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Oct 21, 2024 at 3:44=E2=80=AFAM Gina P. Banyard = wrote: > Hello internals, > > I would like to propose a short RFC to make the return value of the sort(= ) > and similar functions more useful: > https://wiki.php.net/rfc/array-sort-return-array > > I intend for the discussion to last 2 weeks and then open the vote. > > Best regards, > > Gina P. Banyard > I like this RFC because I have a distaste for any function/method that always returns a single value -- the return value indicates nothing usable. I also find that I prefer to avoid array_walk() because I can't elegantly nest it in other function calls or return/print the traversed data. Might the transition be simpler if the naming convention is standardized to have array_ meaning "returns the input [sorted|shuffled|traversed] array" and without the prefix means "modify by reference"? That naming convention will not look absurd among other native array_ functions and prefix-trimmed functions will afford developers to continue using the original modify by reference behavior (if they have performance or memory reasons). | returns copy of array | by reference | | ---------------------- |---------------- | | array_sort() | sort() | | array_rsort() | rsort() | | array_asort() | asort() | | array_arsort() | arsort() | | array_ksort() | ksort() | | array_krsort() | krsort() | | array_natsort() | natsort() | | array_natcasesort() | natcasesort() | | array_usort() | usort() | | array_uasort() | uasort() | | array_uksort() | uksort() | | array_multisort() | multisort() | | array_shuffle() | shuffle() | | array_walk() | walk() | | array_walk_recursive() | walk_recursive() | Good luck regardless, mickmackusa --0000000000006efbb70624f0bbb3 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Mon, Oct 21, 2024 at 3:44=E2=80=AFAM G= ina P. Banyard <internals@gpb.moe> wrote:
Hello internals,=

I would like to propose a short RFC to make the return value of the sort() = and similar functions more useful:
https://wiki.php.net/rfc/array-sort-return-array=

I intend for the discussion to last 2 weeks and then open the vote.

Best regards,

Gina P. Banyard

I like this RFC because= =C2=A0I have a distaste for any function/method that always returns a singl= e value -- the return value indicates nothing usable.
I also find= that I prefer to avoid array_walk() because I can't elegantly nest it = in other function calls or return/print the=C2=A0traversed data.
=
Might the transition be simpler if the naming convention is = standardized to have array_ meaning "returns the input [sorted|shuffle= d|traversed] array" and without the prefix means "modify by refer= ence"?

That naming convention will not look a= bsurd among other native array_ functions and prefix-trimmed functions will= afford developers to continue using the original modify by reference behav= ior (if they have performance or memory reasons).

| returns copy of array=C2=A0 | by reference=C2=A0 =C2=A0 |
| ---= ------------------- |
---------= ------- |
| array_sort()=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0| sort()=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 |
|=C2=A0array_rsort()=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0rsort()= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0|
| array_asort()=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0=C2=A0asort= ()=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0|
| array_ars= ort()=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|=C2=A0=C2=A0arsort()=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0|
| array_kso= rt()=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0=C2=A0ksort()=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0=C2=A0|
| array_krsort()=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|
=C2=A0=C2=A0krsort()=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0|
| array_natsort()=C2=A0 =C2=A0 =C2=A0 =C2= =A0 |=C2=A0=C2=A0natsort()=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0= |
| array_natcasesort()=C2=A0 =C2=A0 |<= /span>=C2=A0=C2=A0natcasesort()=C2=A0 =C2=A0|| ar= ray_usort()=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0=C2=A0usort()
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0=C2=A0|
| array_uasort()
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|= =C2=A0=C2=A0uasort()=C2=A0 =C2=A0 =C2=A0 = =C2=A0=C2=A0 |
=
| arra= y_uksort()=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|=C2=A0uksort()=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |
=
| array_multisort()=C2=A0 =C2= =A0 =C2=A0 |=C2=A0m= ultisort()=C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0|
| array_shuffle()=C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0shuffle()=C2=A0 =C2=A0 =C2=A0 =C2=A0 |
| array_walk= ()=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| walk()= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|
|=C2=A0array_walk_re= cursive() | walk_recursive() |

Good luck regardless= ,
mickmackusa
--0000000000006efbb70624f0bbb3--