Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:73484 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52166 invoked from network); 31 Mar 2014 09:00:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Mar 2014 09:00:43 -0000 Authentication-Results: pb1.pair.com smtp.mail=inefedor@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=inefedor@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.181 as permitted sender) X-PHP-List-Original-Sender: inefedor@gmail.com X-Host-Fingerprint: 209.85.217.181 mail-lb0-f181.google.com Received: from [209.85.217.181] ([209.85.217.181:51279] helo=mail-lb0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 64/C0-44499-9BE29335 for ; Mon, 31 Mar 2014 04:00:42 -0500 Received: by mail-lb0-f181.google.com with SMTP id c11so5450838lbj.26 for ; Mon, 31 Mar 2014 02:00:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:subject:to:date:mime-version:content-transfer-encoding :from:message-id:user-agent; bh=cVlGe4x632XtCh1t1s6FuuZSOkoRGzTe+4kXlmOZI80=; b=v5S36TigtCn+y4UHlQK9mC2MtTgvSyp3ubBol8zpcm7PApfZMVn5pAIlJmUnzZy0cM aRnLgBN20K4Y2cVcSk7QRRnFB9e0IVWbXe9YJNHsE23DaomeNBw0kThti5TewOM+55ze 1tyQloSGnwLwOmnIzVBLnXpXq82Z+CcJckTgMwwF6QdNFjh99f1a+HYVi46Gbb9xEI6+ xGPXwM+tl3Fg3Kf0pBv144KFt+65r7wHvV74Xz/x/4NQ8qIsuAjFrhFykMQzF6+Psj/r S3XeG+M/nWfO2f1YKibKUoDPoMOCZOigYzm3HQ0jD8waof2RxvI+0jwwzGNMpklhTqb/ d9vQ== X-Received: by 10.112.186.98 with SMTP id fj2mr399185lbc.54.1396256439248; Mon, 31 Mar 2014 02:00:39 -0700 (PDT) Received: from nikita-pc (93-80-62-168.broadband.corbina.ru. [93.80.62.168]) by mx.google.com with ESMTPSA id el7sm13420227lac.10.2014.03.31.02.00.38 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 31 Mar 2014 02:00:38 -0700 (PDT) Content-Type: text/plain; charset=koi8-r; format=flowed; delsp=yes To: "internals@lists.php.net" Date: Mon, 31 Mar 2014 13:00:37 +0400 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Message-ID: User-Agent: Opera Mail/12.16 (Win32) Subject: usort callback should always return integer (not float) From: inefedor@gmail.com ("Nikita Nefedov") Hi, I've just stumbled upon this limitation in sorting (compare) callbacks. Is there any reason why we can't handle floats in this case? I think it would be nice to be able to return float from the callback because it's often happens that all it does is just `return $a->someMethod() - $b->someMethod();` (where someMethod() returns float) or `return $a["something"] - $b["something"];` and to make it work I need to write additional if statement. I think the reasoning could be complex behavior of doubles? Especially comparing doubles. But will we see any double-related pitfalls when all our code does with it is `return retval < 0 ? -1 : retval > 0 ? 1 : 0;` (so essentially - compares them to zero)? I made a PR [1] on github for 5.6 version. I think this change is pretty small and could go into 5.6 not breaking our release process rules? Though it WILL introduce some BC breaks for userland code that uses floats. But this code was already broken when it was relying on old behavior. [1] https://github.com/php/php-src/pull/638