Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116896 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 35240 invoked from network); 19 Jan 2022 00:44:21 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Jan 2022 00:44:21 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9464D1804A8 for ; Tue, 18 Jan 2022 17:55:12 -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=-2.1 required=5.0 tests=BAYES_00,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-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (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 ; Tue, 18 Jan 2022 17:55:12 -0800 (PST) Received: by mail-lf1-f46.google.com with SMTP id x7so2851866lfu.8 for ; Tue, 18 Jan 2022 17:55:12 -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=IC6ZE9TP6O+wxO8D50fSIZIxu8G5uYFNRp4e3y6tFy0=; b=HB2oqP14K8rsViaIDyGC2MUpkn9RiOPqzgNrHM0dZKtAY7MPxx0YeNjmV+GNkkAFyi 0Zm4XvR0IGlUcx0oiUYwfWoR98wcP3eSy8H3b/giueVxs9A1ah9nskasaNWLvSRaAT9V pvkaIfBGwCeDP5xuHVTu2Ljel9mcBNGREjqWFNFj/KFaofNTzx5Mrk3cS1vrtwHsymei 2fTCRmY2UbeGANRBw7HS89o0/wzTast1dCseXoScU0n0axAu63XfzFs+IO82UeWvXu7C ZELs1PAW6C+ZZQ+HWkHPFVOHNlOFvqWeTIgAE5TS/VNw2voPexzmXfosUcdZfh0fbQYa K2yA== 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=IC6ZE9TP6O+wxO8D50fSIZIxu8G5uYFNRp4e3y6tFy0=; b=WlLtHEAXt8NHjEp6i2yudBwSCiNH/dMuJ7K1IDxYxU9gJ2TfYcWj0ds1AdPr8XYpLZ sPK3Zh+Vyf2RIl2jvpmV7NkMMdEnFwFWbBCzaBZPWI1BTs9sNvt8JYsyMHbxAHrsF5Df Y56R1hVcG2PHlGEMK6G4wtdnCxQWGzxw/8iqAjdeUV8abvR+H1yIOwBgOgFRID4IJ+Ul CYrDZE1JVzjjkDlD8zk4EAv8NTOJCZuh5vWVSqcN/hueJ34V7xclHdnSbBXr589xjjm4 RAU9jiUGcCf8lwPSPGsN/pXWKCpj34bBbPHQ91Blte00v3Qdf9xcXnsby4MXAS2DDLD7 8Fgw== X-Gm-Message-State: AOAM532YC5FQvPGGJQReJPWueMBG/6AtnvLQWcGZAQX/P991hEPjOZ0I rkS7odCKdE7Gjr7MDoSsGA4xkOVeUYtO/LlPzIg= X-Google-Smtp-Source: ABdhPJzqM/0Sg2f268pNGdnie394OpozWbjU80zHgMPMlZ5rVUrOlS0EAz13MI2vRDbrsnW+favhh4cte0SQ/p2sAHg= X-Received: by 2002:a05:6512:10d2:: with SMTP id k18mr23720277lfg.640.1642557310517; Tue, 18 Jan 2022 17:55:10 -0800 (PST) MIME-Version: 1.0 References: <1641335738.195767637@f174.i.mail.ru> <5a4aebf8-e592-4517-8930-d18b112ef1fd@www.fastmail.com> <5a99809d-afda-546c-5a11-a4f0f821aa37@korulczyk.pl> <6E50C348-9452-40E1-ACE8-06DED11C9136@gmail.com> <9070564d-e138-81f6-c757-812d8962416e@korulczyk.pl> <23f78a61-a73e-eaa3-861f-75e9bca28485@korulczyk.pl> <262352f2-a3e6-272d-1118-5455497217a7@gmail.com> <6ABDE9F5-C69A-4FEE-9736-F2DED514184A@newclarity.net> <3543d7e3-9a26-25f8-8c48-d646431e84a2@gmail.com> In-Reply-To: Date: Tue, 18 Jan 2022 17:54:58 -0800 Message-ID: To: Rowan Tommins Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000000443bc05d5e5ad72" Subject: Re: [PHP-DEV] RFC: Trait expects interface From: jordan.ledoux@gmail.com (Jordan LeDoux) --0000000000000443bc05d5e5ad72 Content-Type: text/plain; charset="UTF-8" On Tue, Jan 18, 2022 at 1:07 PM Rowan Tommins wrote: > > Fair enough, that's a reasonable use case, thank you. I could quibble > and say that "self" or "static" would probably work in that particular > example, but I suspect that would just lead to an unproductive spiral of > example and counter-example. > > Not even a separate counter example actually. Static analysis, including in IDEs, will mis-type the return value as being the trait itself within the trait. So for instance, in my example I used the add() method from the trait in a separate method within the trait. If I return "self" or "static", my IDE will think that *within* the trait it is returning itself, even though traits can't be directly instantiated. (Or more accurately, it won't be able to understand what other types it may satisfy.) This is something I've had to do some real design gymnastics before to get around. I encountered this in a situation where I needed to check between a ComplexNumberInterface and a NumberInterface in the math library I maintain, since they behave differently for the same operations (which was an example of my motivation for operator overloads). Jordan --0000000000000443bc05d5e5ad72--