Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118240 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 55508 invoked from network); 10 Jul 2022 19:03:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 Jul 2022 19:03:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 50C601804B1 for ; Sun, 10 Jul 2022 13:57:33 -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=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 10 Jul 2022 13:57:32 -0700 (PDT) Received: by mail-ed1-f42.google.com with SMTP id m16so4176866edb.11 for ; Sun, 10 Jul 2022 13:57:32 -0700 (PDT) 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:content-transfer-encoding; bh=dHChMBGIH35YHXpGHVCDwAcXDk7rAK6oywOO1xs58UU=; b=5U4E7k+0+CM2PqKZT39TrJZ87sAKEPycZkqQvlwmRn60DfpG5R3YfqKu42sQLtCcPZ CDCJFqOmXHL4JycNOBVLGM8w061Noa1XujTe4X1hfEXA/OP2+NOOBkFpc50qpIaecFj/ UYw8K2FGWTM7xFuP7U8I1KUO0jR2aQRZvnuN6jI3EAuMfIAcKkY74tgVGTqRU2pRnGMP DFxdlU42favlaXPc2Uo0wkWVN6qom0y9KtZ/dL+uwhFotkqvLtg0RnAk9QovdT3DDyWb JTDld1JRxmkyO0P21Vs7+FIYEG75DMXnUrzimD2Eowx2C/R6jS8DMv9wyH7fUWyLW8g9 7T+g== X-Gm-Message-State: AJIora+MTXa4ceGrV0ymR7wu1O+OsawO9pOffmuRk7EYoFzygnIIkl67 fHeNDg8mC6vJH2op9rhSKgo5qXGKVcM= X-Google-Smtp-Source: AGRyM1tPhWY/WJQ5RK2R5mAoVzTAYiA2nEkLXJH78SbOkDhb+7weHWROQfIJjIEb5Yo73iHNWVeWTQ== X-Received: by 2002:a05:6402:4410:b0:434:f35f:132e with SMTP id y16-20020a056402441000b00434f35f132emr20499912eda.215.1657486651565; Sun, 10 Jul 2022 13:57:31 -0700 (PDT) Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com. [209.85.128.42]) by smtp.gmail.com with ESMTPSA id fs6-20020a170907600600b007121361d54asm1889008ejc.25.2022.07.10.13.57.31 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 10 Jul 2022 13:57:31 -0700 (PDT) Received: by mail-wm1-f42.google.com with SMTP id l42so1968344wms.5 for ; Sun, 10 Jul 2022 13:57:31 -0700 (PDT) X-Received: by 2002:a05:600c:41c7:b0:3a2:e8fd:fe52 with SMTP id t7-20020a05600c41c700b003a2e8fdfe52mr24643wmh.123.1657486650901; Sun, 10 Jul 2022 13:57:30 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 11 Jul 2022 05:57:19 +0900 X-Gmail-Original-Message-ID: Message-ID: To: Marco Pivetta Cc: internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] [VOTE] Constants in traits From: sji@sj-i.dev (shinji igarashi) Hello everyone! > traits are pretty much unnecessary in the language. I was writing an email to introduce and defend the trait use cases and it exceeded 10,000 characters, so I decided to post the content on gist and include a summary in this email. Here's my opinion in detail for those interested. https://gist.github.com/sj-i/7981487f879bd9aad8f57a931de1591e I hope it will be used as fodder for future discussions on what traits shou= ld be in the future. Also, if anyone has other opinions on use cases or weaknesses of traits, it would be helpful if you could explain them. Here is a summary of the content. IMO, the following are possible valid use cases for traits, and actual use cases may be a combination of several of these. - Provide a default implementation of an interface - Achieve multiple inheritance - Split class implementations between machine-generated and handwritten, et= c. - Port code from other languages that have similar mechanisms to trait - Share implementations of classes coincidentally having the same functiona= lity At present and in the future, traits should be used for relatively minor us= e cases that are not easy to achieve with compositions. Some of these use cases can also be addressed by the introduction of simila= r features, such as interfaces with default implementations or real multiple inheritance. I am pessimistic about such competing ideas surviving the vote= in the PHP RFC process because of the very existence of traits in PHP right no= w. However, if there is overwhelming agreement that traits should be abandoned while the need for language support for the use cases itself is agreed, the= n this will lead to a future where such alternatives are introduced. I would be OK with such a future if it is promising, but if you do not have such a strong foresight, please support the modification of the existing tr= ait to make it a little more manageable, as a backing up plan. Thanks! -- Shinji Igarashi 2022=E5=B9=B47=E6=9C=886=E6=97=A5(=E6=B0=B4) 18:46 Marco Pivetta : > > Hey Shinji, > > On Tue, 5 Jul 2022 at 23:39, shinji igarashi wrote: >> >> Hello internals, >> >> I've started the vote for the Constants in Traits RFC: >> https://wiki.php.net/rfc/constants_in_traits >> >> The vote will end on 19. July 2022. > > > I voted "NO" on this. > > Reasoning: > > * traits are pretty much unnecessary in the language. Since their introd= uction in PHP 5.4 their usage went from "let's try this out" to "how do I b= urn this with fire?". I don't want traits to expand in scope: they already = do enough damage with their built-in accidental complexity. > * invariants shared by trait (example in the RFC) are generally to be se= parated to clear invariant objects/functions/static methods, instead of bei= ng put in a trait > * a trait does not know the public API of its implementor either, so `se= lf::SOME_CONSTANT` inside a trait points nowhere sensible, since there is n= o clear contract on the possible implementations. Referencing symbols of th= e implementing class in a trait is a clear mistake (again, an example from = the RFC) > * this expands trait compatibility checks, introducing a number of poten= tial error scenarios that are unnecessary (due to the already mind-boggling= over-complicated `use TRAIT1, TRAIT2, TRAIT3` semantics) > > In practice, while this may make on surface because you can declare const= ants everywhere, declaring more stuff on traits is problematic. > > From a technical and detail PoV, your RFC is well written and implemented= : it just solves a problem that doesn't/shouldn't need solving. > > Greets, > > Marco Pivetta > > https://twitter.com/Ocramius > > https://ocramius.github.io/ >