Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125817 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 3A0C21A00BD for ; Mon, 21 Oct 2024 00:18:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1729470033; bh=bqeFj7y1V8STiwSTCzNvYZgPQ5GrQrdp3mh9czRySZ4=; h=Date:Subject:To:References:From:In-Reply-To:From; b=h9K6LOx9ID7d0YScWopb/NR+kQ1Y0Cl9un8eduE4zA0AQfmfMxbbvq97FYDmLqE5V O+9QirjJIP9j/put49Ks3YU3g/r3r8CXc6oyZFvdN5hxuaYAIOIK/EzbDTD6Dyya/r uxsf9HCZ+Ba7eaf2WShHJqJkhtVj/QTN6qCs1BokZoyPIyVvEChQvj14aocE/VA3RH XD6s/C6OJ+b28d7rEgkk6kw4z8adnEGiatlOmg2FV2NKxzVozMxlpI1jfJ3v58fH3s MWSNBEEH2hdKRH1KM5IPESeBnaKgvAOrdDlh1x/jBPx7txkngGgqI47jlflzu9E5DU 7s7oskCu+SvNw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 45464180059 for ; Mon, 21 Oct 2024 00:20:32 +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.8 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DMARC_MISSING,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-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 ; Mon, 21 Oct 2024 00:20:31 +0000 (UTC) Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-43155abaf0bso38051995e9.0 for ; Sun, 20 Oct 2024 17:18:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=scriptfusion-com.20230601.gappssmtp.com; s=20230601; t=1729469886; x=1730074686; darn=lists.php.net; h=in-reply-to:from:content-language:references:to:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=q6LtAhm7ejL3z2sBJ6Hz4Z24hyVBcXWThzovqYIoPKc=; b=saS5U+IJR188mGFd+ZIhWDy2g+ulaE/nok5wEbeD42GYA7XmB17nZQ+o2j5C0SZb6C G36+osWN3pLFQNLqHcFVqdQXtywqZoic4YxSEwL9+7ET1eT+biVs+LJKAn+wiB8WlVYE n+N/BfXFL7eR947qH8u45t+LVag+DnpliWp+nEhiQXx4v0kfWy7uiNMxGEDakdvoAFyU owUlTXuuR7bwcnpy65b+WoLx9mfFFMn2y8lGpB1jvQXWxOIzH3107tQSHBd8tJE19Ne2 f/0t8qpYmlF/fDQHwK8U4yKy2Xu1Rlaqz33aA28yHWqgf624a+UOjyGaEYCE3quEwwVc o/Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729469886; x=1730074686; h=in-reply-to:from:content-language:references:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=q6LtAhm7ejL3z2sBJ6Hz4Z24hyVBcXWThzovqYIoPKc=; b=AfOKWgOzEd0dplAwpLDz+Fbs/zIFSqpmYHbaSaKQKLMGL92HPF19P7Ld85MWZoTCG5 bRlnLkDxCoOP/XdX3O2T32xF62y7+QB7r2TvFv9k6H2Sxr5h2+l/ZAjnu3/mMgeBT7w6 8ZPHW8E90md1CkTUntFQr8qwHTaSaTC7TkG88Tpr6I4oj0KSZLrwZ27h83hOURRlh07W eRMv3o/S5Ei3jjy6NCPglh41J0lN1PgacQjhLgoSLlG21xemNxvkTh8yskCIHLO2yLdU 4QzvIhM11h096ClUXU67xbZYV5FBwIEH8kUTGIri1VCqnzwtcWU6pAqO0vqfA8u0Ubod +rmw== X-Gm-Message-State: AOJu0YyQ+HVWNhwCkxP4oWcZhDH2Z0N4WBpmzyhJvw49XpDDu26tSKoM 3D6sZivn6Y6nGihPimtI7Hi/wAk8Edxu9ox2l2Su9hqV/fYiH9eLQlLGuzrXPv2TDwKwq/p4Ucg 5 X-Google-Smtp-Source: AGHT+IEJJkEu7Qk8diF25JtRuX6f+t+GM/pTzOtx/T8AxbYBVLBtVbITycwCj5EV3xn7AAgf2dvygA== X-Received: by 2002:a05:600c:3d9b:b0:431:54d9:da57 with SMTP id 5b1f17b1804b1-431616ad787mr75318535e9.30.1729469886354; Sun, 20 Oct 2024 17:18:06 -0700 (PDT) Received: from ?IPV6:2a01:4b00:bf09:5101:adda:e4f4:ca68:fc26? ([2a01:4b00:bf09:5101:adda:e4f4:ca68:fc26]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-37ee0b944fbsm2877348f8f.72.2024.10.20.17.18.05 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 20 Oct 2024 17:18:05 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------S8rjXHz0P0SmzjcdA0DlRJ3l" Message-ID: <00f19678-bbd1-49e1-99f6-8a9b78b962aa@scriptfusion.com> Date: Mon, 21 Oct 2024 01:18:04 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [RFC] Change behaviour of array sort functions to return a copy of the sorted array To: internals@lists.php.net References: Content-Language: en-GB In-Reply-To: From: bilge@scriptfusion.com (Bilge) This is a multi-part message in MIME format. --------------S8rjXHz0P0SmzjcdA0DlRJ3l Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 21/10/2024 00:16, mickmackusa wrote: > On Mon, Oct 21, 2024 at 3:44 AM 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 I like this in theory, but array_multisort() and array_walk*() already broke your proposed convention:( Cheers, Bilge --------------S8rjXHz0P0SmzjcdA0DlRJ3l Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 21/10/2024 00:16, mickmackusa wrote:
On Mon, Oct 21, 2024 at 3:44 AM Gina 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 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

I like this in theory, but array_multisort() and array_walk*() already broke your proposed convention :(

Cheers,
Bilge

--------------S8rjXHz0P0SmzjcdA0DlRJ3l--