Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116857 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 93829 invoked from network); 10 Jan 2022 17:11:48 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 Jan 2022 17:11:48 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 220C51804C4 for ; Mon, 10 Jan 2022 10:20:34 -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_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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 ; Mon, 10 Jan 2022 10:20:33 -0800 (PST) Received: by mail-lf1-f48.google.com with SMTP id x6so47427940lfa.5 for ; Mon, 10 Jan 2022 10:20:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=75jcNqRh5Yva7jNczbPVtCYWBgOqAGPBdFCcIwjOaAs=; b=e8o72OTx1QCkXzI4Li2tHjaw2aBTziWLeI/rqgFYEK0VFJscuQt1gnY4ZDI73BuMV7 n78WtSwHieZFmTwHYPoAsWqWhHYI/nhHX1jaPz7HEh6toGEgNAMsDZgmjeDZeo/9YHhg wZQ/eIB95+9vWt+XLsOioG4rOSaY/R0y/rY31d7GZo2kAUsvqLeDibciG61F0PTrT+VU 0NvBSIe7A8kgNd33lFPJvF6xPKnfpKEdzSosq8hStNVP9DktMTn8wfbWmfisFp5f5OQR eilgHNKXZAOefC6X/OzxJkpicqTHJd8EDm9yhTzEWrz/9nh8IV7ov8kchpv6xZg2gS4Q xHsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=75jcNqRh5Yva7jNczbPVtCYWBgOqAGPBdFCcIwjOaAs=; b=xnpf0mm2Z3g+EcC7nhG3JCqPCRMMOeLnsGJSOYgLcKyD6xxrmZBxCsNXZmTlKyl6cL 1O/zLvcMwrAj8G2/KSuiwnnyccsJPNchnsgK6a5XgHKilho/kNQPYbDOPVk6BxH3S5M2 ESF/FjFNXT/gnQ1hoQ+WoN7GBOlPhXpCSfjbbnGiUNRdcYzZL+k+hAhICYSFTz5wwUzK FTJpW5hxAkfenIYpHLDWIiS7fZME5UjLzmSpZAFyCfGugglvlRDHPNKGLy31tR6Bbk1W Ksg+NI54cumvE/STZY02Ggh4+vod6aGhGQPOF977kRzKHQIRRO8gr5NZFwxGT5sKgMqY S5hg== X-Gm-Message-State: AOAM531EqfLULMwRG8//x8WSo+bGVTP5JGCEtAqOmQJ119hI8WAmIXXn Y8rx+8OPdsWyYjWXUb/DPQrHVVwIXfgVvOsuDCfEDd6m X-Google-Smtp-Source: ABdhPJys8JR+kAUsrrgoieIURCx6bvBLzbhGHCJ8c68oQVpGi+dARC2CpMbIpGwjDIgzQ7oEcaqXa9rDZRkwT7Ha7Y0= X-Received: by 2002:a2e:a585:: with SMTP id m5mr471090ljp.228.1641838832164; Mon, 10 Jan 2022 10:20:32 -0800 (PST) MIME-Version: 1.0 References: <1804801.tdWV9SEqCh@come-prox15amd> In-Reply-To: Date: Mon, 10 Jan 2022 10:20:19 -0800 Message-ID: To: Guilliam Xavier Cc: =?UTF-8?Q?C=C3=B4me_Chilliet?= , PHP internals Content-Type: multipart/alternative; boundary="0000000000005ea3c605d53e640a" Subject: Re: [PHP-DEV] [VOTE] User Defined Operator Overloads From: jordan.ledoux@gmail.com (Jordan LeDoux) --0000000000005ea3c605d53e640a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Apologies. I think I saw this, but then was distracted by other matters and lost track of it. This will not work because it will first try A->{'/'}(B) that throws a >> TypeError? So it means what I was able to do for floats, cannot be done = for >> my new classes afterwards? This is inconsistent I think. It also means i= t >> is not possible to extend any existing class with operators interacting >> with a new class, meaning you can only use operators among classes aware= of >> each other, most likely from the same package/library. >> > This is something covered by the future scope Polymorphic Handler Resolution. Essentially, to resolve this issue the types need to be checked for inheritance during the opline evaluation. That's something that would be a fairly easy to do in a very unperformant way, so I wanted to do that as a follow-up RFC in order to put real effort into making it something that would slow such oplines down too much. > The second branch of the if is dead code, as $matrix1 * $matrix2 will >> always call $matrix1->{'*'}($matrix2, LeftSide) and never the other way >> around. >> This means that $operandPos is useless in all cases where operators are >> only typed againts the same type, and points to this design solution bei= ng >> wrong. >> > Yes, for implementations only hinted against themselves, this would be true. The main other strategy would be to use a static implementation that takes both operands. This has a few downsides: 1. While it is still possible to access private and protected properties in such a case, doing so is awkward and not at all intuitive. 2. The boiler-plate code for checking types in order to figure out which side (left or right) is the called instance would be required for nearly every implementation. So some code was saved for some situations, but more code was added for all situations. 3. There is no situation in which these will *actually* be called statically. They are *only* called when an object instance exists, because an object instance is required in order to use with the operands. Such static implementations would only reduce code (in my opinion) if this was combined with method overloading, but that's a totally separate bag of controversy and difficulty. > There is =C2=ABWhy not interfaces?=C2=BB in the FAQ, does that mean that = operators >> cannot be added in interfaces? This is not stated clearly in the RFC. >> > No, these can be added to interfaces and abstract classes and final classes. They can even be added to enums actually. What that part is saying is that this RFC doesn't provide interfaces such as 'Stringable' for each of the operators. > Also, it is not clear if operator overload will affect comparison >> operations used in core functions such as in_array, sort and so on. >> Does implementing operator =3D=3D allows using in_array to find an objec= t in >> an array? >> > The in_array() function unfortunately uses its own comparison internally. This is something that I would want to add as part of the implementation step, yes, but it's not currently in the PR that's linked. > Which of these internal functions use =3D=3D and which use =3D=3D=3D, whi= ch is not >> overloadable? >> > Internally, these functions use neither, because they don't generate an opcode. They do the comparison on the ZVALs themselves. So each of them needs to be special cased. > Does implementing operator <=3D> allows sorting of arrays containing my >> objects? >> > The same as above applies. It doesn't actually generate an opcode, so it needs to be special cased. The good news is that this special casing would actually be pretty straightforward, since I also wrote helpers for things such as extensions to more easily handle these sorts of things. Jordan --0000000000005ea3c605d53e640a--