Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108999 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 11685 invoked from network); 13 Mar 2020 12:44:17 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Mar 2020 12:44:17 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9D07A1804E6 for ; Fri, 13 Mar 2020 04:05:53 -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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,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.15.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 13 Mar 2020 04:05:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1584097550; bh=Y2vsL/wDDy+Rr4Qx701C94vUHLuZidjLAdWYkr52EoY=; h=X-UI-Sender-Class:Subject:To:Cc:References:From:Date:In-Reply-To; b=jLFVISHXlSEhmF2b8niAPTX2d8qk/KIoVvQE6gEbbB1J4MrQE3kV8FTl6yFJ+6iG+ eCeNwUoHLvZ2DQ+2qOtenKY+UY2a23YeNc3yKh/l1Kv3/BGZqa+6c0KVCtpIzoNa4w 6APh/JwgzZN7CB6Q2y6dI1JxAiQ6pwFqCtmcLFq4= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [10.140.116.64] ([141.35.40.27]) by mail.gmx.com (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MiJZE-1jr1Im36N4-00fRzF; Fri, 13 Mar 2020 12:05:50 +0100 To: rowan.collins@gmail.com Cc: PHP internals References: <005101d5edae$7b7c3e10$7274ba30$@gmx.de> <8776962f-71ac-0ee3-a1b8-42eb2926eef0@gmx.de> Message-ID: <849f81ee-40e3-999d-a8b5-2701af2ec483@gmx.de> Date: Fri, 13 Mar 2020 12:05:50 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:MEH+E6cL9XattxzwWwPkQHRg/+8S8zrK7Vf+ELbthogEft9BHJm Uu8giuhg4r9cJ5tUVJxavIcOyBDIxoEPszqVHps/W3uS9N34mNcSS8SUY8SojWrmWXbNZii 5HH5NEY/XlLiiY80V+RGZ19syQT3PIVXD8tWEn7tt9sAZbgG6MT8WNQsClPuHmhLnDVo3ZF eQUPqfUFwadBHT4c2+0dg== X-UI-Out-Filterresults: notjunk:1;V03:K0:gnM/GJX1evs=:PjinzSS067+8tb1Rr2N8Fy g5bQ8Cuk421/FLjKIne+BCijTnBYi/PPmpjsxdZUoEUFvFg20X0LSBrnc1Q71Bwv1ZDWy4iU+ iOGkSVbN4KABhMj4olXjAubglwdkQ9haAHBaWg6c1kkHMf3U7X0jCU5xtHY7IYpxECqihM0mC fZhSDNwj+xFq8UKO3Y93FPbStvu73C4CVpza0RyfNkDFGrJxjpVJFdZOax5doG5RtAyXxPuFD sk6sTw/3EozMDkY1clkKW0SaiF1CkHA6vZQszMyTRxHoX10xsOhp5Pclu7gxdz/IwOmr+5A6s gBVEWQrGLdaZHZ/ZLSZtSclB5q/n45BYL1acDg2AIBpKLXuEtir4cWG+vD9xGCWQD7dYvOgJP y1DtTxPysFVUGuARitKAJYCGaUFSCj8eW3BkitCvBRAGjtIny9j7i23Q+a2WrW9UKOAJxMTOb sK9ItSi4En/OoTCDipvjX1qGqFOzMNVmMFO4w4a4rMAh+XsFMXUmsH4hJF2lI5yDlgpHv/TtB rC5flQE3gMsHglsjS3CEnLauMfCfynlVUYY+lbp9+bx51VqUXhZ7BaZJSxElSwlB9HEyyugCM 5mLMegto0cT9NkVYGN1a421DOFOKTQnyZCeo1FDnXTHmVkJfh4nJ0UaNJDYd4R2Y+pCiVpIv3 vmLZpFj4JQTPN0QELJyZJXX5wnMjfLLgEgjaoUFTiFquKJ6/ae1RbT+veM/2s9rh1+M2XEmhO 2KKDZv75NhyNWx6tkpyhPwd6RFbc5fYdTfCbk+suB0N7sAEiUL4puNNz9y1jo8jZWmKWZn4os o4qVy4DuU+i6qbFt/jlYtdzLSEaTpXvU87EaCmSHGpz67l5AgEg28J6NIwp4qtjBrrwGLZ3yB eLUIf23osuONqv2bJWPyEBvXoqCqhnG5z9lfxzNWgOKoxCi8VnlDPDg+udfiKbvPaYZcWRBwv iYbYtL0o0eT3N013392Hj/j/73lFJmHKMK0Ar2p9TKvskCwvoL1pukeHP2I6Sjm9nd8qnF+iQ jY6G/pTlCSRAL6Tun/Jy5SMF+E7QrwNksUwi7EOmiY7tW5jJQcfLXwXfQl0u2nbfLlH/rK/w6 /JWXc3CTlV5/ehXJuiYlm+By0eNDqfVSm6URyiMc7v6YJNhPtZ2CQ42dqwPu+fC9kMA+0/dLz uMidjJETK3e68TWd9YnQG48OELgYiP2oPym2VYpJ72e4/N9u2cD5adYxz2sieP3W4Pl5G9foh e5p8kf+P7my0LzGmH Subject: Re: [PHP-DEV] Re: [RFC] Userspace operator overloading From: jan.h.boehmer@gmx.de (=?UTF-8?Q?Jan_B=c3=b6hmer?=) On Thu, 12 Mar 2020 at 10:06, rowan.collins@gmail.com wrote: > On Thu, 12 Mar 2020 at 08:31, Jan B=C3=B6hmer wro= te: > >> On 11.03.2020 at 10:50, Christoph M. Becker wrote: >> > On 11.03.2020 at 10:22, Nikita Popov wrote: >> >> Does anyone else have thoughts on the ability to specify the support= ed >> >> types in the signature? >> > I agree that we should not introduce (this special case of) overloade= d >> > functions. >> >> I have thought about this the last days, and I agree with you. Therefor= e >> I have removed this feature from the RFC. >> > > > I've been thinking about it as well, and am not sure what happens _witho= ut_ > it in a case like this: > > # initial class, only overloads + on instances of itself > class A { > public static function __add(A $lhs, A $rhs) { > // ... > } > } > > # in some third-party library > class B { > public static function __add(A|B $lhs, A|B $rhs) { > // ... > } > } > > $a =3D3D new A; > $b =3D3D new B; > var_dump($b + $a); # calls B::__add($b, $a); OK > var_dump($a + $b); # calls A::__add($a, $b), which is a TypeError > > If the engine doesn't catch the TypeError, it will never try B::__add($a= , > $b) in the second case, so presumably the TypeError will just be thrown = to > the user, which doesn't seem very helpful. > > Perhaps the simplest solution is to have a restriction that the operator > overloads _must not_ specify types in their signature? > > Regards, > > Rowan Tommins I have implmented your suggestion. If an operator handler has typehints, a= n error will be thrown, similar to the behavior if they would not have the required amount of argu= ments or were not static. The restriction that some functions can not declare typehints is not compl= etly new, e.g. constructor must not declare a RETURN typehint, so I think it is not completly inappropriate to prevent your mentioned pro= blems this way and I will most likely add this to the RFC. What do others think about this restriction? Furthermore I added a check that no arguments are passed by reference (lik= e with other magic methods). We can not really prevent that a user manipul= ates passed objects (as they are always references), but at least for builtin values (int, string, etc.) it should not possible= to modify their source. Also this would lead to problems, as the 1 in som= ething like $a + 1 can not be passed as reference. Regards, Jan B=C3=B6hmer