Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125827 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 3E3AB1A00BD for ; Mon, 21 Oct 2024 20:42:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1729543471; bh=ju6ZWB4fqeHGeTLfMP6a7JU6mPEUhELWSU6iVUqPcmQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Atm2oGx0DzD+nqA4zsTBndQbPF+SZHIyIZtS1itt3yBa4UESw0TtKj1M+YugUZTCI mETtmOvdmh405ExWZn2wszADYdfQo9qGmZyx7wIwJpxXHMr1KyxfWZlrdlU1TYpnLH HIR4M6WeOkSGelNG/JZpeO5xvM3gwnb9wgKB2DXpn/Pjo9yFhNbQUDGlHJe1qmoO8A eBalszrDEr2mVz6WhFpF6Fn044yTWli0Ra8DkvKj5ekIgVUAl5IVYvReLwOj/Hz/vr Wt83M6eJOnXkQRO6e5CGlXjT2qPt0dKNoc8eyUlRWoxvw/zWtiRV8Vleg9Akg2odvm 9cuofzQ6cdP/g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2888B18006F for ; Mon, 21 Oct 2024 20:44:31 +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-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (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 20:44:30 +0000 (UTC) Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-5c941623a5aso10002400a12.0 for ; Mon, 21 Oct 2024 13:42:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729543325; x=1730148125; 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=C4SVwInymHYq+NjtI9fa463XOFQGMrdcUYd8LyHFyDs=; b=BoaF17Byb4xTViWnj4NDjG0AQaR4d7b+YtKUTm+2Lg1ot9Q2IOs8PBw8ZYMwlWDvOL 4NxiUv4hp3ho/lvE5cbcIqd/ym4A8jDbLCgS0sS6UK4A9yM/3AnVBz1CfJqPNS8mES3K +ZChOkUNjD3hGw/CXC9DPmYTpVSZrNKvoUgoJ5iUngBHQKph3jrCb12PfOZK8bRATcbI 3s6ncLy8EImHtiLJ2FSQYoHcgLzfqBq9ZJKpAt78gmX7WKvi7pyG2MYWJ2pBbfuzD1n9 deXiFM52CXq1yJ4JhdKLTqZLJkM8AU+Hb+UHwXATyNJ+90y+xBZLZTzNH8dR3ntHaVU1 nu9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729543325; x=1730148125; 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=C4SVwInymHYq+NjtI9fa463XOFQGMrdcUYd8LyHFyDs=; b=tH+8N8yJQDr8YwVXdAHbzzHTPZeCgIEX5jYBGFWscJjILvIV/mJ95chencWbe9GwOe tkBRKrcrbVh4V+DDvjugyg8AG+EnUfNjN4GSzrElSXttpnHM29Y/3rjfp2PbC5OnEEi4 /TeqTa/1TbdHthgHoBe/rvlix3sPqgzvqe/YTpMaZkht6cDUcyLnvlYN4n3bXUpN1yMm g5v7rkWu1PeICUxcg/fLCUDdy4qbDQVqOTMlXH47FTC8uJa0GOpVn44099d0UuxPbL3o FAeyZ2NgwgKHrXS4uAgh/aXxbn5KEX4fdJ/MBOzKGHeLu7RNfcZ6tChO7fsJWElTcvVr vQIA== X-Gm-Message-State: AOJu0YxjeZBsc0XHnULVSPTFGbGUJ89PuK4hM8HzkHJzklnSNlRpzNgZ lVvwjZxOLn5smlXAYGztJ1rAst1uurU+oNOss/CGJdYIooOlF9dIUjPlUoGX6CavylnlcmhPLPP nndDgOyDxufDxiuJimQJdpdFFSng= X-Google-Smtp-Source: AGHT+IE0f1736N/XfTg8IuUp0PqQMQfe2mlCbnseufAr5WiCNaaYjtstLktWdmNy9NC7nFU9mAiF7I7XlHqOcyBPRQc= X-Received: by 2002:a05:6402:510e:b0:5c9:7d63:14db with SMTP id 4fb4d7f45d1cf-5cb79472121mr949404a12.10.1729543325226; Mon, 21 Oct 2024 13:42:05 -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: Tue, 22 Oct 2024 06:41:53 +1000 Message-ID: Subject: Re: [PHP-DEV] [RFC] Change behaviour of array sort functions to return a copy of the sorted array To: Valentin Udaltsov Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000861ebf062502af92" From: mickmackusa@gmail.com (mickmackusa) --000000000000861ebf062502af92 Content-Type: text/plain; charset="UTF-8" On Tue, 22 Oct 2024, 02:30 Valentin Udaltsov, wrote: > > What if instead of this proposal we reimplement all of the array > functions in a different namespace and fix a lot of other problems and > inconsistencies? > > Array\map(iterable $iterable, callable $mapper): array > Array\sort(iterable $iterable, int $flags = SORT_REGULAR): array > ... > > -- > Valentin Getting off-topic here, but array_map()'s parameter order matters. Because it can receive one or more arrays, the callback should be the first parameter to afford, say, spreading the rows of a multidimensional array during transposition. The same "spreadability" logic should apply to array_*diff*(), array_*intersect*(), and array_multisort(). If we were going for consistency, always write callbacks as the first parameter for any function that has one. In other words, parameters which can be repeated more than once must be list as the last parameter. It is clear that this RFC is seeking success by making the smallest possible, very practical change. While it is healthy to explore deviations, I like the RFC on it's own because it makes PHP more adaptable to writing elegant code with fewer temporary variables. Mick > --000000000000861ebf062502af92 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Tue, 22 Oct 2024, 02:30 Valentin Udaltsov, <udaltsov.valentin@gmail.com> wrot= e:

What if instead of this proposal we reimplement all of the array
functions in a different namespace and fix a lot of other problems and
inconsistencies?

Array\map(iterable $iterable, callable $mapper): array
Array\sort(iterable $iterable, int $flags =3D SORT_REGULAR): array
...

--
Valentin

Getting off-topic here, but array_map()'s parameter order matters.= =C2=A0 Because it can receive one or more arrays, the callback should be th= e first parameter to afford, say, spreading the rows of a multidimensional = array during transposition.=C2=A0 The same "spreadability" logic = should apply to array_*diff*(), array_*intersect*(), and array_multisort().= =C2=A0 If we were going for consistency, always write callbacks as the firs= t parameter for any function that has one. In other words, parameters which= can be repeated more than once must be list as the last parameter.

It is clear that this RFC is se= eking success by making the smallest possible, very practical change. Whil= e it is healthy to explore deviations, I like the RFC on it's own becau= se it makes PHP more adaptable to writing elegant code with fewer temporary= variables.

Mick
--000000000000861ebf062502af92--