Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102496 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11596 invoked from network); 27 Jun 2018 16:14:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jun 2018 16:14:58 -0000 Authentication-Results: pb1.pair.com smtp.mail=chasepeeler@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=chasepeeler@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.208.181 as permitted sender) X-PHP-List-Original-Sender: chasepeeler@gmail.com X-Host-Fingerprint: 209.85.208.181 mail-lj1-f181.google.com Received: from [209.85.208.181] ([209.85.208.181:44400] helo=mail-lj1-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 98/50-01794-008B33B5 for ; Wed, 27 Jun 2018 12:14:58 -0400 Received: by mail-lj1-f181.google.com with SMTP id t22-v6so2084984ljc.11 for ; Wed, 27 Jun 2018 09:14:56 -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=04PeBKUq5RC2FcixboIuYDrqb+Zl2fWK/TLs/jBH+ck=; b=ACTQRnwK3tvAnJKZi7l0QaQ6+R2mFYO3KLgqcKOx2R8DSjv2Z/51esYVClEpoggNxk 8fHatFh871mhwworPxdQ3ybsv1vLBH8jty2gg3E16PHcRuh0W+CDzT17lTdohAgcXca9 0DMTX04lrNh49dW3WtaLXLTYLRwBrdpGr2kQ6+3Izb19uBA+YdGo9VDj+r+K1h9NR1Ue ndOtX0NA+DrRz0qd/MiQg2RocM5ul0iHeDJRyVDZVwT4Y3GKLclHTlLowxllHfBqZ1yp gM6gndksG49dh70w3s0G0rh+icgc+jHtC8RrnEuZY54PPeWCLWdH+oF2OuPror3k+VzM hIgw== 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=04PeBKUq5RC2FcixboIuYDrqb+Zl2fWK/TLs/jBH+ck=; b=UaVwnwx4cVY5guQolywjdl1BW1gGjS15Xho5WbtEl3CSlF61lT2tdZeMtZkiwPk1xJ jwtOfEbM0AUf2n5+vmG+5vzOv2pYTjSxWujWu5X/OD4rLr1g+/dm/s6u2lvFspLG45h3 jsk0JBxeEbU+/zb4eK9PnxMDaDs9ZJDYbjY7uftvXBTzFZHEoQriKjKpRAVuMFgFXFbg 9ppN3ioclkSgPt+l88/nVTKRb1hTAyGuOgwe51UReBwSUsw19J7WojcrPuN+YMVQOtnD Sg/Hi+W5dAIbKWlHkodUtjkfQgdJjb5Gzm/dXMyY/B9AIOhed+K2BWXoO8+qeKFKPKYO xvHg== X-Gm-Message-State: APt69E3/O1mVMnTFy0fSaKRuOpsqQGY1mXzO7z0e/eH4NXB4CXZKnuvP DgIri+LQ91LjhULM+cvcxyJiFvy03tBUyeqmHqQ= X-Google-Smtp-Source: AAOMgpdaMxM7SKWwxUIlu+O00L18bSHg2D7qlTVJ4wA0ShjEbu8t+OyRBdicas+KyLuUK/s/6cKqGf0cBI71p8epnEc= X-Received: by 2002:a2e:8455:: with SMTP id u21-v6mr3202112ljh.66.1530116093691; Wed, 27 Jun 2018 09:14:53 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 27 Jun 2018 12:14:41 -0400 Message-ID: To: Rudolf Theunissen Cc: netmo.php@gmail.com, internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000003acdef056fa1ea00" Subject: Re: [PHP-DEV] [RFC] User-defined object comparison From: chasepeeler@gmail.com (Chase Peeler) --0000000000003acdef056fa1ea00 Content-Type: text/plain; charset="UTF-8" > > > > If $left operand and $right operand both have the magic methods, it will > call $left->__magic($right), otherwise, if only the right one has the > handler? What if the right one has compareTo and the left has only equal? > you probably should add a table that explains which method is called > depending in the availability of the two magic methods in the operands. > > I think $left == $right => $left->__equals($right) makes perfect sense. $left dictates fallbacks, since $left is the one invoking the method. If $left doesn't have __equals, then it uses __compareTo... if it doesn't have either, it falls back to the original way. Bottom line, the existence or non-existence of either method on the right side doesn't matter. As with all type juggling, you run the risk that ($a == $b) !== ($b == $a). The other option would just be to force both objects to define at least the __compareTo method, and if one of them doesn't, it falls back to the old way. I woudn't go as far as requiring they be the same functions though... existence should be good enough. Maybe throw a warning if used for classes of different types or where the methods are different - but if I have class Apple and class Orange, and want to compare them, I should be able to do so! Has implementing this using an interface? Just like ArrayAccess defines methods that allow object to be referenced like an array, Comparable could provide methods (equals and comparesTo) that would override the comparison operators. Personally, I like magic methods, so I'm good with the RFC as-is. -- -- Chase chasepeeler@gmail.com --0000000000003acdef056fa1ea00--