Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:49845 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73747 invoked from network); 3 Oct 2010 11:47:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Oct 2010 11:47:27 -0000 Authentication-Results: pb1.pair.com smtp.mail=ceo@l-i-e.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ceo@l-i-e.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain l-i-e.com designates 67.139.134.202 as permitted sender) X-PHP-List-Original-Sender: ceo@l-i-e.com X-Host-Fingerprint: 67.139.134.202 o2.hostbaby.com FreeBSD 4.7-5.2 (or MacOS X 10.2-10.3) (2) Received: from [67.139.134.202] ([67.139.134.202:4186] helo=o2.hostbaby.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C3/53-52683-E4D68AC4 for ; Sun, 03 Oct 2010 07:47:26 -0400 Received: (qmail 46202 invoked by uid 98); 3 Oct 2010 11:47:24 -0000 Received: from localhost by o2.hostbaby.com (envelope-from , uid 1013) with qmail-scanner-2.05 ( Clear:RC:1(127.0.0.1):. Processed in 0.041361 secs); 03 Oct 2010 11:47:24 -0000 Received: from localhost (HELO www.l-i-e.com) (127.0.0.1) by localhost with SMTP; 3 Oct 2010 11:47:24 -0000 Received: from webmail (SquirrelMail authenticated user ceo@l-i-e.com) by www.l-i-e.com with HTTP; Sun, 3 Oct 2010 06:47:24 -0500 Message-ID: <01f9082a02170415e626b2d65d090460.squirrel@www.l-i-e.com> In-Reply-To: References: Date: Sun, 3 Oct 2010 06:47:24 -0500 To: internals@lists.php.net User-Agent: SquirrelMail/1.4.21 [SVN] MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal Subject: Re: [PHP-DEV] Expose compare_function() to userspace From: ceo@l-i-e.com ("Richard Lynch") On Thu, September 30, 2010 9:44 am, Adam Harvey wrote: > Unrelated to the Comparable RFC, are there any objections to adding a > function that simply wraps compare_function()? It's depressingly > common to end up writing a construct like the following in comparison > callbacks, so I think we might as well encapsulate the pattern in an > actual function: > > if ($a < $b) { > return -1; > } > elseif ($a > $b) { > return 1; > } > return 0; > > If I don't hear kicking and screaming in the next few days, I'll slip > this into trunk. I can provide a patch/RFC in advance if there's > demand, but it'll be about as simple as you imagine. :) > > The one thing that I would like bikeshedding^Wfeedback on is the name: > cmp() makes the most sense to me, since it lines up well with Python > and (to a lesser extent) Perl, but if there are concerns about > potential name clashes with existing code, may I suggest > var_compare(). Get your votes and/or suggestions in! I don't really think we need this in core. I mean, yeah, I may have written the same function a few times, but it's not exactly brain surgery. (which I've been through so I know :-) Except for handling non-int input, which you probably won't do in the core function anyway... Seems kind of a pointless bloat to this developer. -1 PS It should be INT_cmp if it takes INT. Or num_cmp or number_cmp var_cmp et al would imply any sort of var... Though I guess using < and > means it would do whatever those operators do for Objects, strings, or resources... Which I wouldn't even want to try to predict and rely on anyway. -- brain cancer update: http://richardlynch.blogspot.com/search/label/brain%20tumor Donate: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FS9NLTNEEKWBE