Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72587 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98842 invoked from network); 14 Feb 2014 10:06:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Feb 2014 10:06:38 -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.215.51 as permitted sender) X-PHP-List-Original-Sender: inefedor@gmail.com X-Host-Fingerprint: 209.85.215.51 mail-la0-f51.google.com Received: from [209.85.215.51] ([209.85.215.51:58780] helo=mail-la0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 49/B2-12906-DAAEDF25 for ; Fri, 14 Feb 2014 05:06:38 -0500 Received: by mail-la0-f51.google.com with SMTP id c6so9238582lan.10 for ; Fri, 14 Feb 2014 02:06:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:to:subject:references:date:mime-version :content-transfer-encoding:from:message-id:in-reply-to:user-agent; bh=f/xEfCZ/2jCCst24KtqSdrR8eqOyjAz/h+lMateTeOQ=; b=SpRkR2zvEic4YY+ajiTDn3Gp7zvklMT17tAeJyKKcIzMyZKqtuItXoF0tyKCMz+H5v AdA/844wdswXoufNIwn9tNQl5/Nj03FMqKzDJUXoPPJes7EFr3A0KPPD6Q01JOmdrBGx 27eYfnoqJQtITIjJxCN9GwnQnGm/xYzSlg3o8lOHxRnIoe9K8BYs5OJng8i050xj144G auFMn+RNrMqgXInBhtZ+JgFEDCSZWsJ6cX7udXKNaYruOH9q608UQpch89usv5tux6ox u8wZ1VwULlGKYcPURtedmaNIpMuTsjGGL4HfruADl4Kbz9Y8n2JgkhyLbLkm71+6nlii cAZg== X-Received: by 10.112.64.7 with SMTP id k7mr1449278lbs.42.1392372394709; Fri, 14 Feb 2014 02:06:34 -0800 (PST) Received: from nikita2206-n56vj ([217.174.184.92]) by mx.google.com with ESMTPSA id k1sm5338146lbc.5.2014.02.14.02.06.34 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 14 Feb 2014 02:06:34 -0800 (PST) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: internals@lists.php.net References: <4ED7146272E04A47B986ED49E771E347BBC71EE997@Ikarus.ameusgmbh.intern> <52FCE4FC.6010204@php.net> <4ED7146272E04A47B986ED49E771E347BBC71EEA16@Ikarus.ameusgmbh.intern> Date: Fri, 14 Feb 2014 14:06:32 +0400 MIME-Version: 1.0 Content-Transfer-Encoding: Quoted-Printable Message-ID: In-Reply-To: <4ED7146272E04A47B986ED49E771E347BBC71EEA16@Ikarus.ameusgmbh.intern> User-Agent: Opera Mail/12.16 (Linux) Subject: Re: [PHP-DEV] [RFC] Combined Comparison Operator From: inefedor@gmail.com ("Nikita Nefedov") On Fri, 14 Feb 2014 11:18:53 +0400, Christian Stoller = wrote: >>> >>> Why not using `$a - $b` instead of `$a <=3D> $b`? >>> >>> >>> Simon J Welsh wrote: >>>> The only real case I see for this is to save some boilerplate when >>>> dealing with arrays. Strings have strcmp(), numbers have subtractio= n >>>> And when you=E2=80=99re sorting objects, you probably want to be do= ing >>>> the comparison on some string/numeric property. >>>> >>> >>> Agreed! It would make more sense to write a comparison function for = = >>> arrays/objects. >>> >>> >>> Best regards >>> Christian >>> >> >> This operator DOES work on arrays/objects. The fact it also works on >> scalar values is a bonus if that's how you want to look at it :P >> >> - Davey >> > > That's why I said, it would make more sense to add a new function for = = > comparing arrays and objects. > Why adding a new comparison operator if we could achieve the same with= = > one or two additional functions? > > And I am not sure, if this is not already possible nowadays. > > For arrays you could do: `array_sum($array1) - array_sum($array2)` > > And for objects you can define a "sum" method on your objects or a tra= it = > e.g. > > trait SummableTrait { > public function sum() { > $sum =3D 0; > foreach (get_object_vars($this) as $value) { > $sum +=3D $value; > } > return $sum; > } > } > > You only have to use this trait in your classes and then you can do: = > `$object1->sum() - $object2->sum()` > > Et voil=C3=A0 :-) > > Christian Hi, DateTime is the problem here