Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118065 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 66211 invoked from network); 22 Jun 2022 19:44:45 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Jun 2022 19:44:45 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3DA531804D0 for ; Wed, 22 Jun 2022 14:34:21 -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_H3,RCVD_IN_MSPIKE_WL,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-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (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 ; Wed, 22 Jun 2022 14:34:20 -0700 (PDT) Received: by mail-ej1-f41.google.com with SMTP id cw10so13267742ejb.3 for ; Wed, 22 Jun 2022 14:34:20 -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=h9F7jsOXq7EYL/H81Y2mZYp2CtXXRw7G3tnogIjFExE=; b=u53eqKZC6EdV30z9AsB0tw/LDEnzYip4gdgoLj1G5qm75WdB6bRV1dLBZYFJwOMpBy hWRA17dgtPFT8T+jVhVwzB5azRT4Sl1pk1764+XBY/MlUEcCXQOwgMg2J4+vKkLihzPY rl7t0VxTCQW0o3rxF1NuIyQWSsPUNB48kKTzo4PaMAqbPZhbaPRaVErl1A5ZIPFwybCF LwJvGYzQlog0uA38xLQnW6WBEibN0WpfBO456VY0i+4r2v54NsKXOQIQR6gF9Gha19Fr XxFYQ6EdxklPA1qui4sKVuUBwpwQ5Mn192d6G1Asw/dGBFRATIOM8dGyXYdGUJuzK+r8 qQhw== X-Gm-Message-State: AJIora/Pu12O2s/H1bz3ybWLXVPm33dGPm4SocviDxVVcI0B2pk4FwJ3 i39P2fBarJJCEhO7wRfjkMd1HimVhg2VN58G X-Google-Smtp-Source: AGRyM1sFJ4v8Xz5jPd45OS/clIRrlItmvHN5QyUYQdHzn6+cEE594cIPta84XaY6Hsm8Tz66djqnJQ== X-Received: by 2002:a17:906:5197:b0:712:2223:d3d0 with SMTP id y23-20020a170906519700b007122223d3d0mr5121761ejk.74.1655933658977; Wed, 22 Jun 2022 14:34:18 -0700 (PDT) Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com. [209.85.128.47]) by smtp.gmail.com with ESMTPSA id ch11-20020a0564021bcb00b0043586bee560sm7182640edb.68.2022.06.22.14.34.18 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Jun 2022 14:34:18 -0700 (PDT) Received: by mail-wm1-f47.google.com with SMTP id m125-20020a1ca383000000b0039c63fe5f64so389126wme.0 for ; Wed, 22 Jun 2022 14:34:18 -0700 (PDT) X-Received: by 2002:a1c:7718:0:b0:39e:ff42:a3b8 with SMTP id t24-20020a1c7718000000b0039eff42a3b8mr419280wmi.0.1655933658256; Wed, 22 Jun 2022 14:34:18 -0700 (PDT) MIME-Version: 1.0 References: <029d3b2e-e8d3-41d0-acc9-7f7514651030@www.fastmail.com> <47080817-4B05-49C9-ABC1-B1EFF55905A7@stefan-marr.de> In-Reply-To: Date: Thu, 23 Jun 2022 06:34:06 +0900 X-Gmail-Original-Message-ID: Message-ID: To: Stefan Marr Cc: Nicolas Grekas , php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] [Under Discussion] Constants in traits From: sji@sj-i.dev (shinji igarashi) Wow, nested blockquotes are disappeared completely in externas.io :-) If anyone is reading the discussion via externals.io and misses the context= , please check the source of the email. https://externals.io/email/118064/source Thanks! -- Shinji Igarashi 2022=E5=B9=B46=E6=9C=8823=E6=97=A5(=E6=9C=A8) 6:04 shinji igarashi : > > Hello Larry, Stefan, and Nicolas! > > Thanks for the responses. > > >>> Why were constants left out of traits previously > >> That! > > So, my working assumption is: it wasn=E2=80=99t something I really thou= ght about. > > From what I've read in the old ML archives of discussions on introducing > traits to PHP, perhaps constants simply were not among the considerations= . > The phrase "constants" is rarely even mentioned in the discussion. > > >> why the default value of a const (and a property) could not be changed > >> by the class importing the trait? > > My answer to this question is that there can be more than one policy for > handling state conflicts, and PHP has implemented one restricted approach > for now and has not yet addressed another policy after that. > > Based on my limited understanding, let me briefly summarize the story. > Please point out if anything is incorrect. > > First, it should be noted that in the original trait paper, the trait has= only > behavior and no state, thereby avoiding the state conflict problem in > diamond inheritance. In the original trait paper, it is assumed that the = state > is provided on the composing class side and accessed from the trait > through the accessor [1]. With this pure approach in mind, PHP allows > abstract methods to be declared in the trait, and the composing class > implements the requested accessors. > > The problem with this pure approach is obvious: there is too much > boilerplate in creating and using traits. Traits provide class components= , > and serious class components will often want to access some state. > During the initial discussions, many messages were sent to internals abou= t > whether to allow properties in traits, and what form this should take. > > By the way, historically, there have been two typical approaches to the > diamond inheritance state collision problem: one is to merge the state of > the common ancestor, and the other is to have independent state for each > common ancestor in the separate "path". Since different use cases require > one or the other, programming languages sometimes have features that > allow programmers to use these two methods selectively, such as virtual > inheritance in C++. > > Where having state becomes tricky is when the diamond problem occurs. > If there are no conflicts, it does not matter if a trait has state. And e= ven if > there is a conflict, if the programming language defaults to either merge= or > having independent state, that default will work fine for half of the use= cases. > > PHP strikes a balance in this problem, allowing traits to define properti= es, > and choosing to deal with conflicts by merging states, and also marking > any conflicting definitions with different visibility or default values a= s an > error, as a sign of an unintended name conflict [2]. > > This is how PHP came to have properties in traits in its current form; I > believe that the story of having data definitions instead of behaviors in > traits have barely settled itself, and the story of constant definitions = was > simply forgotten or put on the back burner. > > While not the main topic, current PHP does not yet provide a way to allow > common ancestors to have independent states. There are several > references to Stateful Traits in older discussions[3]. Stateful Traits de= fault > to trait state as trait local, but allow the programmer to selectively us= e > merge behavior as needed. On the contrary, since PHP defaults to merge > behavior, there may be a future extension that allows trait local to be > explicitly declared. This option has even been mentioned in the old > discussions, but it has not caught the attention of many people and has > been on hold for more than a decade [4]. Perhaps it is time to reconsider > this also. > > >> And I'd also be happy to see an implementation of this before voting > > Yeah of course! It is generally working on my end, and I'll send PR withi= n > a few days after adding a few more minor test cases. > > [1] https://dl.acm.org/doi/10.1145/1119479.1119483 > [2] https://externals.io/message/51007#51072 > [3] https://link.springer.com/chapter/10.1007/978-3-540-71836-9_4 > [4] https://externals.io/message/35800 > > Thanks! > > -- > Shinji Igarashi > > 2022=E5=B9=B46=E6=9C=8823=E6=97=A5(=E6=9C=A8) 2:39 Stefan Marr : > > > > > Hi Nicolas: > > > > > On 22 Jun 2022, at 17:31, Nicolas Grekas wrote: > > > > > > > I'd like to start a discussion on an RFC to allow defining constant= s in traits. > > > > https://wiki.php.net/rfc/constants_in_traits > > > > > > > > I'm looking forward to your feedback, including corrections on Engl= ish wordings. > > > > > > > > Thanks! > > > > > > > > -- > > > > Shinji Igarashi > > > > > > I am initially lukewarm. One thing not addressed in the RFC that sho= uld be: Why were constants left out of traits previously > > > > Hm. This isn=E2=80=99t something that I remember coming up specifically= back then. > > If it had been discussed in more detail, I=E2=80=99d probably have incl= uded it in the RFC. > > So, my working assumption is: it wasn=E2=80=99t something I really thou= ght about. > > > > > > > and what has changed to make them make sense to include now? (I don'= t recall, honestly, so I have no strong feelings one way or the other yet.) > > > > I am not sure there are reasons to specifically exclude them though. > > The RFC, reading over it briefly, and having been away for very long fr= om the topic, seems sensible to me. > > Taking a very restrictive approach, seems sensible to me, too. > > > > > I'm also wondering why the default value of a const (and a property) = could not be changed by the class importing the trait? This sometimes hits = me and the original RFC doesn't explain why this is needed. > > > > For constants, I=E2=80=99d lean towards not allowing changes. > > If you need to parameterize the trait with a value, having an abstract = method return it seems a much clearer way of doing it. > > Then all parts of the system know =E2=80=9Cit=E2=80=99s not a constant= =E2=80=9D and I need to cater for different values. > > > > The reason for the strict policies on property conflicts was to keep it= simple. > > Be conservative, and avoid silent bugs. > > > > > > Please take everything I say with an extra pinch of salt. > > It has been a long time. > > > > Best regards > > Stefan > > > > -- > > Stefan Marr > > School of Computing, University of Kent > > https://stefan-marr.de/research/ > > > >