Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108974 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 19485 invoked from network); 11 Mar 2020 12:05:02 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Mar 2020 12:05:02 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A8DD91804D3 for ; Wed, 11 Mar 2020 03:26:07 -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_H2,SPF_HELO_NONE,SPF_PASS 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-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 11 Mar 2020 03:26:06 -0700 (PDT) Received: by mail-lj1-f181.google.com with SMTP id w1so1692200ljh.5 for ; Wed, 11 Mar 2020 03:26:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Jz9vBXEVVS4TTjedbGT6ehDYRemjXKlj9nD6XU5qsok=; b=t6D5RrzeVFmB620OOIELil++x+7lqZzLRC1Ex6I1duuHsISJq2YifKnAICgU58vlxf JLK1Nc36/vBGEMLziGeL2dVvNMYi8bwFzNQ6lCR1a0yvFN98qec9HEUkv/1RMfyZ0M2p hoQPSt0tGdzBeJj88iP7bTH71zduQyUfB6U4TfkuIR30EAD3o2M9csySkJU5B4zG3Dx7 qN0zI0925bksCt07gRHyeJlhcU0EevDoHXItotE6LwlS1x4u6C1+CYaYqkZAcRa4OjGO TL35sSJeWoRCwb4I5+zCejCy/c1+7cMo5/VJZ8GOejHwo5kGEtlG+BjpOMaVP/07WJxv 9olQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Jz9vBXEVVS4TTjedbGT6ehDYRemjXKlj9nD6XU5qsok=; b=qf6qNzqEoeyzf7WUMDNFQtDs6LeRMwJEo/0mk8cRu6GkXo0M3m0krd4VFTahrD+5m/ /ISgWGvkd1TCSQhw/0uWm0Buhpk0jOCIojh2q5xLGsXSCJiJW1WdaRPfp8RWF1OamkB5 GboxqmB4ptf+ewHQ8P+JNiYBC/8xD4eLe57u7cFhMFsJSJ47dIxfcFnbTs91rspnrIwv tjadeTdOAzL8QG3Nz6UwwPFjcQbNh/tV8Ji7RtyxmkMFDSND8VRD47hF4xI3AGxCt92s cUcqzkvSyGvHeJFUbdK95XwPbbYNdWaJPt+XTNTlm5zC017OtNLGcNy8zYoPY/CtCEVD etBg== X-Gm-Message-State: ANhLgQ3AvwocQuiHb4ny8Nhq1NPbsxSRKEMeupQYNP16xWmFBXWiNzSE LyFAtZHD803J/Bu9CZzmxnAcJsP4rb/aVH2ate4Toa4e7yyeWQ== X-Google-Smtp-Source: ADFU+vv/VsqYr92ljneZ6gFSwS8xWrEtPSITnzQTVWM33wxHIsA191lLDKdn6sy8I4f88ltiWk0t7byTmLB6LbtXNvg= X-Received: by 2002:a2e:9a96:: with SMTP id p22mr384718lji.258.1583922365317; Wed, 11 Mar 2020 03:26:05 -0700 (PDT) MIME-Version: 1.0 References: <5e619238.1c69fb81.59711.d7b8SMTPIN_ADDED_MISSING@mx.google.com> In-Reply-To: <5e619238.1c69fb81.59711.d7b8SMTPIN_ADDED_MISSING@mx.google.com> Date: Wed, 11 Mar 2020 11:25:49 +0100 Message-ID: To: Andrea Faulds Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000efc80b05a091a940" Subject: Re: [PHP-DEV] Make sorting stable From: nikita.ppv@gmail.com (Nikita Popov) --000000000000efc80b05a091a940 Content-Type: text/plain; charset="UTF-8" On Fri, Mar 6, 2020 at 12:58 AM Andrea Faulds wrote: > Hi, > > Nikita Popov wrote: > > > > I've implemented this variant now. If the comparison function returns a > > boolean, you get > > > >> Deprecated: usort(): Returning bool from comparison function is > > deprecated, return one of -1, 0 or 1 instead in %s on line %d > > > > once per usort() call, and we retry with swapped operands to ensure > > compatibility. > > > > Regards, > > Nikita > > > > I think that message could be a little misleading, because any negative > or positive value is valid, not just those of magnitude 1, right? IIRC > strcmp($a, $b) doesn't just return -1 and 1, and of course this is also > the case for the classic ($a - $b). > I've update the message to say: > Deprecated: usort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or larger than zero in %s on line %d The astute reader will notice that this is equivalent to "any integer", but I think phrased this way, the meaning should be clear to anyone familiar with the basic concept of comparison functions, while not mentioning -1, 0 and 1 in particular. Regards, Nikita PS: Yes, I'm aware that you can also return a floating point number. No, you should definitely not do that, because it's going to get casted to an integer and produce wrong results if the numbers get large enough. --000000000000efc80b05a091a940--