Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108339 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 85938 invoked from network); 31 Jan 2020 22:07:02 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 31 Jan 2020 22:07:02 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 96DD5180571 for ; Fri, 31 Jan 2020 12:18:13 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS8560 212.227.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 31 Jan 2020 12:18:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1580501888; bh=JhyoP3f/Pqqb44dOGP/QpZ3QuXR2ZMIg6tQS6VSbnmc=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=PdwiBuhgPvoXlARECXSAeZY4odyOZw+pOhHI1a2O+SImIp4bdUHg2nDs/XbzeE94N ypu/Vxz1eox01T3BpCE9L11Cr7g5I9Or0ZLvWZKCXwz4g45wYBKZ0ckILGkhbEwwRo Li+Nk4aauWXRplHrkO71CnUG6Uv61/WywNQBVjMQ= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from DESKTOPF2PTDOD ([141.35.40.65]) by mail.gmx.com (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1M6Daq-1ivQsJ3t5U-006jWm; Fri, 31 Jan 2020 21:18:07 +0100 To: Cc: "'PHP internals'" Date: Fri, 31 Jan 2020 21:18:07 +0100 Message-ID: <007601d5d873$8d087cc0$a7197640$@gmx.de> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdXYaLHY/k01z6yaTrCFoqYo9xIuqg== Content-Language: de X-Provags-ID: V03:K1:MDKeRZManjxIsg0VdIZw5+8VRqETh5NgOjFoE5tzlR6D5TdLIAX kBv4NUv6FQNjKjytTE85US9t9XiRZCCdD/jv7OvFvC3aqgBPtKX/N/wwXSLwX7GC1BRixzs tcBsqPd/Uz86/Zt0GJd0Fjgsb6YfBdf5RwsPC9fkX4NozaYYM39/oie2TnsuTqVV+FtcD5g cCNcuUjkak2zqM9txvTBA== X-UI-Out-Filterresults: notjunk:1;V03:K0:I5c0SFF998c=:Vz8Bvlp+bP6TOAOZ9vEWrV 9EeKmdldA0fGMJIrYEE8MetPPNgjHF9cyDkg9RcHb4YSx3uXZZa51hGnjyBV1+dKNqNbOgI/i 5/QI8okaJdYAqrMqXiTAdUToZrfuBkVjEW+i25eg2WTO+2TDShPRf/RzDdFAOhxuwl0OkEQdQ aWP6tugDAV0hIRaGrygrOqjRwKnXgKaZfg4s3QgKZUvIt9d4UQjtLgPQRpe4chdODxBoPzDhQ jHQQIVSheJ6LvZdprLoMoM5HY8mghKa1FuHDOJN7zXGj/mOjZWyhLDZmtgQ5ckn67lH5DCrDz A5MnpHddBH5KFK20Bjr9DGe7yOeNiUTiQFssEVO8oEohWImmGgqbNszCt3Zeb4ahuwt2YVawn 86YgIkLvwL6RaV1TpNRdEKvoRH9gK4V/rYPbPEGwSnEZ/CU+3EN1s7PjofGxTt253w5sA2lKV QjLWMp3P7/6Fbjb3zFwrHjCrpOCoe0huqUoxmwrprp9DQGAxP8yV93eRoWmQVYG3h7/eku5Jq 2Vjhpuf4lcOaitKO8oAfLEP/82lZs2WRPp0ITqRwbm85yJ+VhLICchsJ3Ix1/BEod1OgEbKvS kE2q7wbnEqzdccs3o4Bc/d41s8Tu+N8UOEFGIeWvfnE2QhAipBNI/YlQrFVYUe7O3NzQCWYCe yObVOABpmhd0oLZiMg+5ItPC9pyNeNViE7aw3vbtTeGmiAwa4IABkLdw29MgpW7r2Av9aRcby 7R44DH7pb9pVl6wDhFy/FLqaYL24bp1j6Uol8nJlBhaDzc36bVQO0Uc1kpOaf6HMi2LfsEb1i Z17pNDrgN5FHw4DXB0O3uPODNTvgWzrBJ534FkhwLElGpkecsEOZKT1TAHIfnZC892CxqACV0 en6qVkhVK873x1rfnsRh5XT1j5h8GWb/w5YO7sTxo4C1MahA3kMa0GlpTrSeJkBClx5JUCT9/ Mob8J+0ThhxM+Q6T3rMczO+zRn26ea+aa163G0Kqp5ITYQVxLM4FsH4CcCV5MidTYKo+cEJQG SFmo2ga+aVpx2bbYVFFWdmiHNxvWmm9YGLix4RvpsYq8V2fJMzlpvDP50qG5IHLtcK8jUWDTO UXQjjSBy3d0pvhCpayg0gFM4sdDwWUd7tXtb7Lm3ajZnD1paKM97VPEwuwuJqPCZm6cAU+Hz2 tAVotmbtG7vqQJWOm6yR5V+AzwWatTay6NYb+PFcXS1hxyENkE9QXtFMV6aIlEWg/YPUUrtVf Fr2YV3+LuXUx4MT8s Subject: Re: [PHP-DEV] Operator overloading for userspace objects From: jan.h.boehmer@gmx.de > I cannot speak to the implementation details. From a design = perspective, I am tentatively positive on operator overloading, with separate method = for each operator, BUT, the big question for me is the rules around type compatibility. > > Can you only compare 2 of the same type? What about subclasses? Can = that differ if a subclass overrides that method? What happens to = commutativity then? Can you compare based on an interface? I do not think the types should be restricted at all. For a numeric-like object like an money value, adding an scalar like an integer or float is quite useful (e.g. $a + 2.5), for things like vectors this would be not resolvable (you can only add between vectors, while multiplication with = an scalar is valid). In my opinion the object should determine the operands types and decide if it can handle it or not (and then throwing an exception). As long as PHP does not allow function overloading with different types (like C# does), I see no other possibility except = deciding on runtime if the type is supported. For sub classes this is more difficult. I guess in the most use cases defining a good operation handler in a sub class is sufficient, so maybe = the operation handlers could be required to be final. Another possibility = would be to let the user handle this situation completely, even if this could = lead to undesired behavior. In my opinion the most elegant solution, would be if an operator handler could somehow signal that it does not support the type passed (maybe by returning null, or throwing a special OperandTypeNotSupportedException), = so that PHP can try to call the operation handler on the right operand = (that is one of the reasons I like passing both operands to a static handler). > Also, I want to reiterate: Any of these operations MUST be designed to return a new value, never modify in place. These operators only make = sense on value objects, not service objects, and value objects should be immutable. I agree with that. The best solution here would be an integrated = support for immutable value objects (which could become quite complex on its = own), but I wonder if it would be sufficient if copies of the objects = instances are passed to the operator handler. The user could then change the = scalar properties of the object like he wants, without changing the operands objects. > Frankly I'd avoid bitwise operators entirely for now. I'm not even = sure how you'd use those... They could be maybe useful for mathematical objects, that define more = than the four basic arithmetic operators (like the cross vs dot on vectors, = or tensor product) or four things like length-safe binary number objects. = Also I would say they are not used very often in normal PHP, so redefining = them as custom operators would be less confusing, then using other operators = for that. But I can understand everyone who dislike the idea of overloading them, = for the reason that their used could become too confusing. If there is to be = an voting on an RFC, maybe it should be split into a voting on the = arithmetic operators/concatenation and a voting on the bitwise operators. Greetings, Jan B=F6hmer