Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109392 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 86887 invoked from network); 28 Mar 2020 16:50:54 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Mar 2020 16:50:54 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 918211804F4 for ; Sat, 28 Mar 2020 08:16:17 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_ENVFROM_END_DIGIT,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 ; Sat, 28 Mar 2020 08:16:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1585408571; bh=UL8b6xpY88IG5+taR+dbEKZ1A3f3+zCn4FtM82SRRA0=; h=X-UI-Sender-Class:Subject:To:References:From:Date:In-Reply-To; b=K5ZKDRd9pLEouQYsSR7tNYIL5Hupk6iUcqdaJwoX/mjhXQPidtfF3nIcaJQg/aL1J E5bjbamrMQgBnJ4aHUO2g570UMVTcki8v/bYTnIHPwmIBE1LyftMrJc/1VTjKTqQr5 YJmVgC+Ipr8+6tkxiC6U2NA94Q/o1QlxHkayEU4M= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.2.130] ([84.179.237.201]) by mail.gmx.com (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MWRRT-1ikIFc0UCR-00Xx5a; Sat, 28 Mar 2020 16:16:11 +0100 To: Andrea Faulds , internals@lists.php.net References: <003701d6013c$9afe9750$d0fbc5f0$@gmx.de> <7a83f950a31d94d5ff2307ac8219db3b7b6482b6.camel@schlueters.de> <12ad7c71-8958-7742-12c4-e83e359c8186@gmx.de> Message-ID: Date: Sat, 28 Mar 2020 16:16:10 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: de-DE Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:5wMXAEkmtVyPNtpPIJolRrtG4AWGCtjBpEwr2zoVIFUvuMi8Eoa bMgO7AlbUiVwxrVgWWBzjzMbgvqH1UK7xMtjkt3rZzHEBBsEZc1ZdY0HonxLtpEnmHe4NOS Pv4BPCRs63Dd/nTUm5GxZD7BYpcNcxofVpbhJ92IaKmADb7UKSBkBeTZgZREr4RpltqzS5n rR4RxY9jPyOokKPbUWUnQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:yQmaVNWhytU=:SY882NX2/t8V5B1lG/qHb5 VnEm3SRfww/UymqHY2wbT+DhbD0HUJKkDXyRJQ3QyRe7Jd4gRLutW5psuUHtPW0uj2fQ98JOZ 9dqXQkOYmAU9fTn4Um1wZh4zlzJpXnNp4NOenha22r+vwJftq09zII/vAiJaSRhvLVx8ERL4G vrMXDNVUIrXNPZG2TqEnBBl3jeSduiTQixnd8iBbdHrGl4G2JofOlz106d2FcDPBsJwi5ztus ODJerwo59KP0Jedg1ykrHk3poRo1J7U62aPM2tHeA4DVOeGTt9Marz6Q1jjOSRo1NlJB7dlxH 7obyj0z1QSO2WcPCpb4ALbfVz0HqBRaWFpyHHwdBC2Xo8QBFQ3Bpnu+C0LIb9W/APFB/Xm3zV l4HG11cXWg2Ol3RQ0a+ewYSEbzCRmL6sht+rKre7Rp0+QVp1rjZchN2x2Hz/Q3Hf9Q2CBPtEC qf9SMfHVIMSEYZdmsAVzg12Z5PbWJQNk/xDW+3mlW8ZZ1cALXCwwkRr/C/0h4+l4fywGy7+vm GWEYd68qNETjMUX43Izb6Jz9prCgArQh7+PZJLQtoYV/kfb2RzRFI+a5pISuwuS4Rt4lNgGbI k/rWIPQLR8Eaj1SUqbrzcoHYIS4g+NFmGhLTtJbWHM9P/ObgLWyAxSZ0Q0NuU1QCM1K/k6zgO m5P6OafKOZG0Mug3cG4owNXVGnkZdwJxtkvAp5ECVDPzxMyC2xhy9thFQoz7xO14bDPiP/QPo GdoYVHCr930VB6t/26SF+H0Q/yBa+ezOIF7q9Wlu7XZVDXbIJnALGcaRec8FjFtZSobVIaztj p1ZgMyMHR3bnxOUNWpG2d1hqXBzfZ2+ViNQL/RDKE27gVVCf/rcwH4caf98KcOAA2WGKNzuAy PgoXiMHGYjFJ4GO3iL65nlhKV+UThQdnIOZRQQQLfyZDz6bTvp7iz+1d1h29aX2APalhwfboh 3DYrC6GN9Th/63W23faeMXX7egjJnVN1diqnXzuImPWeGlGh0Ep+L/MOKKq0vphvlePj0VY5E W5Pg/TBQwvqNbHOpem4eix7GELCw/jQW+c010uH7o23uQzzGYQlDuDKisnHBOR2E5wM8Mg4Mo J2B4W8zwnoQp22ARWu6+5qRexvpikpFwagsGYZmjiGgMxZgiqPfYSXEZ38pRZAwt1Y/GnzADj O5JRZmbqofpmaUMrELruGPRHMcv9CPfXauGN7rZLZpfhWAGphki1iJObY/cuJo7he4nNVKYwn Cs/WB/SANwOM1kW3W Subject: Re: [PHP-DEV] [VOTE] Userspace operator overloading From: cmbecker69@gmx.de ("Christoph M. Becker") On 28.03.2020 at 14:29, Andrea Faulds wrote: > Christoph M. Becker wrote: > >> This "try left/right" approach is how operator overloading works for >> internal classes[1], and apparently, it works quite well, as long as it >> is not overused. > > I think =E2=80=9Cas long as it is not overused=E2=80=9D are the key word= s there. We have > a very limited number of internal classes with operator overloading > right now, and the authors know about what other such classes exist and > therefore can design with them in mind. But once any userland PHP class > can use operator overloading, you could start seeing uses of operators > where the left- and right-hand side are classes from unrelated libraries > whose authors were not aware of eachother, and that could create strange > problems when one or the other library is updated with operator overload > handling. > > Consider Arnold's example: > > =C2=A0=C2=A0=C2=A0 $a + $b + $c - $d > > We are not constraining operator overloading to just be for number-like > objects, it can in principle be used for absolutely anything. And floats can be used to store monetary values, and to do calculations, and apparently, that is actually done by some. Was it a bad idea to introduce floats to the language? > $a here > might have an overload that works for any right-hand-side object, but > then once $b adds its own similar overload in a new version, the code no > longer does the same thing when it's flipped around ($b + $a), violating > the normal expectation that `+` is commutative, and that's before > considering what $c and $d might do! If, for example, the + operator is overloaded to add something to a collection, the normal expectation that + is commutative is already violated. Operator overloading should definitely not be used for "anything", but only for those rare cases which resemble math operations (frankly, I would not have not supported __concat() at all). Also, overloaded operators should be programmed defensively, i.e. they should not accept arbitrary arguments (how could that even work?), but only those they can handle. If implementations adhere to these "rules", I don't see real issues. =2D- Christoph M. Becker