Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102544 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58790 invoked from network); 30 Jun 2018 23:07:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Jun 2018 23:07:43 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.177 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.128.177 mail-wr0-f177.google.com Received: from [209.85.128.177] ([209.85.128.177:37195] helo=mail-wr0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6F/84-15351-D3D083B5 for ; Sat, 30 Jun 2018 19:07:42 -0400 Received: by mail-wr0-f177.google.com with SMTP id k6-v6so12022742wrp.4 for ; Sat, 30 Jun 2018 16:07:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:user-agent:in-reply-to:references:mime-version :content-transfer-encoding:subject:to:cc:from:message-id; bh=IQVsETlITzc0b0tfezxHG31FtMY5pb6b9bA4JmmQUXE=; b=JBxjZS0jjQnjE5F7ffQdt+4kQFzRWXYMznupE6wgB7LfcEkGWhbdyjjsWQ8BV95iKz xMoAPqNJhMoDSXTaJYqnwmtHg4jRs1T2+FDbtVdZTP6bqjN3U85zQ42FM+pyHTMkDceb X/5irodQ+t2/CToE1+piY6hrz+cKHoZ4o8F43nMFhCDgCBnIXwHpvFeKLPoVOho15wDj L9+cxlKM5q+Vu/tdrLlT1LffkXI8MVzg+2jGg1wdaqzTvTbBv/aQaw/DsqwDVO5LwK+c gk0xRdoDJDk69Ga2/DD7wxXHwEo97k6ofJCrwFnmO6semyJoCCZHhY+gfXCPAg6+9onp MxaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:user-agent:in-reply-to:references :mime-version:content-transfer-encoding:subject:to:cc:from :message-id; bh=IQVsETlITzc0b0tfezxHG31FtMY5pb6b9bA4JmmQUXE=; b=Flm/KQu2U/12nSeDowI9B7uWiggIzIsnJcXV3PyETABFEVmwXUQgAWuGNesKRnK+W7 LX1uJdt5TBCY7B/8lMl4JYY/81kGOqB+9b7ffxXaYwG75iqb9OQP5b9XKudblk1bEw45 Wh6Q/rfYGjoySIbYNba+xZRRUvPd9MUBwV1Fsfnmqjfk+8chRXz/8uwTWFE8ma+sQ7LU KmaW/ssc3wwUNPR3IG/HulgsyeYPHmO84zx+iDtZ0q5g5VFZ0m3HhCvFcJ8juF74JlXu kCXiKJex2HFKXbDOct8VQQiBNGIctyfFnnI8S+QmqW31Iv9SA/OcSM7cSay27kjLivCU IlHQ== X-Gm-Message-State: APt69E0d5fBFxODedvcOP4KtKVpSuLaJnRNG/Otzzh0F4P5o5nFaxaSP bmGk+vJ5kTGqidjHAUBu/kcwhALu X-Google-Smtp-Source: AAOMgpcH3C46cbXFEaUADGZ2sdHI0RLgBN/zX94EmhHvqEaK+kh3ZCuIkKrD63yip0ehadcBGfuAlw== X-Received: by 2002:adf:8acd:: with SMTP id z13-v6mr15523119wrz.22.1530400058805; Sat, 30 Jun 2018 16:07:38 -0700 (PDT) Received: from [10.109.13.163] (94.197.121.212.threembb.co.uk. [94.197.121.212]) by smtp.gmail.com with ESMTPSA id s13-v6sm2542319wra.22.2018.06.30.16.07.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Jun 2018 16:07:37 -0700 (PDT) Date: Sun, 01 Jul 2018 00:07:34 +0100 User-Agent: K-9 Mail for Android In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable To: Rudolf Theunissen CC: levim@php.net,internals@lists.php.net Message-ID: <91F0875C-74EC-4115-83F9-5E87A02051C9@gmail.com> Subject: Re: [PHP-DEV] [RFC] User-defined object comparison From: rowan.collins@gmail.com (Rowan Collins) On 30 June 2018 19:04:27 BST, Rudolf Theunissen wrote: >We're proposing the ability for a user to determine how a class should >be >compared to another value=2E The ability to change the semantics of the >comparison operators is an unavoidable side effect=2E Absolutely, I agree with the intent of this RFC=2E I think what I was sugg= esting is that if people in future want to overload the operators specifica= lly, we would want to provide an overload for <=3D> that was separate from = __compareTo, so that you could overload that without breaking things like s= orting=2E >> I think __compareTo() and __equals() could act more like a return >type >hint, and either throw a TypeError straight away, or attempt to coerce >to >the correct type and throw a TypeError on failure=2E > >Currently they do attempt to convert to boolean and integer, >respectively, >but that doesn't achieve much because you can still return nothing in >either case and the coercion would be 0 and false=2E Apologies if this is covered in the RFC, but does that apply wherever they= are used? For instance, what will the following code do? class SpaceStation { public $shape; public function __construct($shape=3D'[]') { $this->shape =3D $shape; } public function __compareTo($other) { return new self($this->shape =2E '>=3D<' =2E $other->shape); } } $a =3D new SpaceStation; $b =3D new SpaceStation; $c =3D $a <=3D> $b; // Error? 0? echo $c->shape; // or will this echo '[]>=3D<[]'? $d =3D $a < $b; // Same result? $list =3D [$a, $b, $c, $d]; sort($list); // Or will the error only be raised here? >The decision whether to accept this will come down to the trade-off >between >flexibility and potential for misuse=2E=20 Absolutely, and for what it's worth (which isn't much) I'm +1 on this, if = it's not documented as operator overloading (which I think is a separate fe= ature) and can't be used to produce values outside the expected type (due t= o coercion or errors)=2E Regards, --=20 Rowan Collins [IMSoP]