Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108319 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 36995 invoked from network); 29 Jan 2020 16:29:22 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Jan 2020 16:29:22 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EE6BC1804AC for ; Wed, 29 Jan 2020 06:39:59 -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=-0.7 required=5.0 tests=BAYES_40,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 ; Wed, 29 Jan 2020 06:39:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1580308796; bh=W5FAwsTEcsivn62+qt5xiIOTHJXQJVaWXkY4v5z3Xno=; h=X-UI-Sender-Class:From:To:Cc:References:In-Reply-To:Subject:Date; b=V3fEIDAtRn9wVyzdjs7WqethaZaO8YQn8K4WjG5YPMQIQ0WV2xobHYdjOtXIxzJmx Lnn8sOeF54xYjHq9pIvdYizymBnb5zN/zvU091gCRiCEXRp2G3mLH/eykuOexpUuwR cHFUBzEt2Pov/cVuwWuW+oAM0ebdFJmEkJCVHaBo= 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 1N5G9t-1jfbab2oPV-0117an; Wed, 29 Jan 2020 15:39:56 +0100 To: "'Nikita Popov'" Cc: "'PHP internals'" References: <00ea01d5d630$b18d4f20$14a7ed60$@gmx.de> In-Reply-To: Date: Wed, 29 Jan 2020 15:39:55 +0100 Message-ID: <012f01d5d6b1$f975a590$ec60f0b0$@gmx.de> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQKXoxxQn2bR4QXrsNNx7hJjE1ZW5AKdGYKYpmklXMA= Content-Language: de X-Provags-ID: V03:K1:+qlTyhkyhrw/YYRdGwoauKwbbB4G4jtgGehcyNqkBzKUB07Rm57 ypwe3Y6HKGVSmmRDHIIBYbM3tH4ztPzaycujXVF1ujmxehzc6FtIS5+/b/FmBAtLJUm6l26 tMy5JhjvP8eqmQ+5Snl6dkdcz1aWU2Bz7Qg5e6eXTTOAcNc1Uv09Axpg8NOFkJdWuu7yXAy UbEL8mHVIDpDVznswl/Tg== X-UI-Out-Filterresults: notjunk:1;V03:K0:oq3//fGKXpU=:cr/1Cv/xZzjpKLT6ZnBl2h Wvk4Oe6eR10N3VEdRo+gmL8ecC9CGCBnaZik9Qr2n2H2ChWRB4gbU8R78rq51JIcNcM6n+pQH R57rsVo5rhmvl2t4PzQBr1LHveX+8VOFrNM21NgLGhbZnKL8hW81ciWk/ev/LJmaLa+o92SzY URPvHhLvwI0hzblNhbNvoZvemqvOvOF64ryDNsONY2MmFAufTMXM8e/KJyIVn7hV7b+EuPoem qc8XREn8IiByIezP9ofzp/i3Svyrvvc85HLw0X4B/XqMuOX1OZMLMKHucI1T0hALgHYHc4Vq+ F+8DkJ8Ln8S9g//Hg+EF5daTKhICf5BdXjhxHQp5lVgykus+3lclPRnwbNS5kQixaorROjCKb dqaB4HI5O5PPsXglpBwycJ8P1MObaouY0/mhAE+2j4Q3IkZDGvOGvYQcerpuLrl2D8I8vac89 8QAMnlmR7rt8yNbgwdCl60Yeyt2qjduF0e1tKrSRUBkZxaNNOWySXwYKLvrpTFMOKiuW2wuYo kdPnuaU+OmATEfREy/NsWEczcWo1dHUGU9522lkfNzjn4g09BqUjX4kSpTMbNo+9z1WJ4T6yu WoFgzQ7j2SOlfzujuOHlxrwV9qbjbiOLkb4FG6ss0YGa5BKQCIpWJb1DAYRyaIXNhx3BOWm9A q9+DP8gaF1OG9nozv3gjopmcF/YiS+NMWtIu/z79eCfxk1/uLv7tnXoFKB2vP4FU3sHswJEeI ZfZ6ECxf8O2k92hVXmmmNQ3vVmoJbbVdHxMAi/1VhZVK8bkCAAiInPGmQpXHH7Efa33zB6koE 1iYaJtsmbflO9fSQixy2y1smWVuqYwgddyrwC0nYK8wIZ1bqVXZ5aUT8M9a0vP4NytMsV1G8E mbG88XQpDYfxJS+w3IVHvoU7AlJeaH/WIfkskxVF3HtrSgYu9uX9ERCiHlTC59RGODDWY9ZNq h7LKDpwPcshmGkaLq+qk6oezT4PpGVqw29yrqsqvV5vB9Ng3wuUwo5UnpxdftNJgLWGuEDaBk Q6K5ORoigPgxh3MwUfGt0kW1btUxcG3/x2Q26oK1Sq7KNd+dIqqoqCSsEOFxjgWPo/qjVAIyS WaOoX00iIq7GkRqGQhCVNO6K2X8HWeAQqA9AvDGQjQqMPDYEIC8J8YrStr45SFSjiQlZNVJQe NWwo7GnDSP76X01PvGwbptsiPOgUHgi3zJzrO4y8vDwvRpKOioSmB+3j/g6v2rNWNHfxJX+ZS DgcnnN2TIBBl/AP37 Subject: RE: [PHP-DEV] Operator overloading for userspace objects From: jan.h.boehmer@gmx.de > I would recommend not handling overloading of comparisons in the same = proposal. Comparison is more widely useful than other overloading and = has a more complex design space (especially when it comes to = accommodating objects that can only be compared for equality/inequality = for example). Comparison may also benefit more from having an interface = than the other operators. I understand your point. There was already an RFC with an similar idea = (https://wiki.php.net/rfc/comparable). I think the idea of having an = comparable interface could be really useful for things like sorting = algorithms (so these could sort any comparable object). The case that = structures must not define an order (but can have equality) is a good = point, maybe this could be solved with two interfaces Comparable (which = defines the spaceship operator) and another one like Matchable or = Equalable (which only defines an is_equal function). I would not split = the comparison operators any further (the RFC mentioned above even = suggested to overload the not equal operator) or we end up with = situations, where $a!=3D$b is not the same as !($a=3D=3D$b), which would = make the code using it very difficult to understand. It is maybe reasonable to split operator and comparison overloading into = different RFCs so they can be discussed separately. But if PHP decides = to offer operation overloading it should also offer a possibility to = compare custom objects, or the operation overloading looses some of its = intended convenience (like the situation in PHP 7.0 where you could = define scalar type hints, but could not allow passing null easily). > Of course there are performance concerns here, and it could in some = cases be significantly more efficient to perform an in-place = modification. It is possible to allow that while still keeping the above = semantics by only allowing an in-place modification if $a has no over = users (something that we can check in the VM). But I don't think this = should be part of an initial proposal. I agree. If there is real need for this case, it could be implemented = later. > Unfortunately, this implementation goes in the wrong direction: PHP = already has full internal support for operator overloading through the = do_operation object handler. Operator overloading should be exposed to = userland through that handler as well. I have seen this mechanism too late, and I have to understand a bit more = how it works exactly, but I agree that this internal operator = overloading mechanism should be used. I think it should be the goal that = internal and userspace classes should appear the same to the user in = points of the operator overloading, so an user can just call for example = parent::__add() if he is extending a PHP class (e.g. Carbon does that = for the datetime class). I will try to build an implementation using the = do_operation handler, when I have time. > Thanks for working on this :) I think overloaded operators are a = reasonable addition to the language at this point. I think the main = concern people tend to have in this area is that operator overloading is = going to be abused (see for example << in C++). There are many very good = use-cases for operator overloading though (as mentioned, vector/matrix = calculations, complex, rationals, money, ...) Some of those are not = common in PHP, but maybe the lack of operator overloading is part of the = problem there ;) Ultimately we cannot really control how people will end up using the = operation overloading, but in my opinion the benefits outweighs the = drawbacks (also hopefully nobody would be insane enough to replace the = print function with << ;) ). With FFI-bindings it would be possible to build cool math/calculation = libraries (similar to numpy in python), that can be accessed easily via = PHP and does big calculations in native speed. I don=E2=80=99t think PHP = will become an scientific used language like python, but sometimes some = higher math function in PHP could be helpful. Also at least the handling = of money values is quite common in web applications.