Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114902 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 84714 invoked from network); 16 Jun 2021 08:00:13 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Jun 2021 08:00:13 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0E3B41804D8 for ; Wed, 16 Jun 2021 01:16:56 -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.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-Virus: No X-Envelope-From: Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (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 ; Wed, 16 Jun 2021 01:16:55 -0700 (PDT) Received: by mail-lf1-f45.google.com with SMTP id v22so2900512lfa.3 for ; Wed, 16 Jun 2021 01:16:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4CsUE9Q3qHZmymJb41K5iQs7333yCJFNpAV1ETsGt0Y=; b=TddKbZQw7C+OKPH+73glciibfAjRjFVhbTr7u0CDDUBl1IjF91yCSB3f9xkHz3pQ7n 7d084PLkq6CI4YDuo8/H9kz1iUxSPX9LVjWAB5P8Igp29ulwBjp3oERp5zMMlRgKsS3R e1b8QoX1I1QKxeQL9EQLFkXOhqUsx/sPK6O9XFG80/MNmPyhrKmHlvfEOfj9Td4gkski B9nqw4XRj5O1jOUg0pZhR1RtC5ePB1m3Fgf0u/9wdKsiP0m1c86h0N5rCwuuvcwGLR3S prjQLMxW+jY5aDMuHCpc7FVNUAIKnKq3E1Po9ykCtS4TCoglRiWXZyJMrbrUNYv4+pwZ V75w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=4CsUE9Q3qHZmymJb41K5iQs7333yCJFNpAV1ETsGt0Y=; b=DPGXrA4qpdU3u6oLXaFW4X9I+dh6MawOeEduRX4C7atPeblzCjm1So/n+wHHIhb5PM 5B+Qd6OB+O3OzhWt1dxrSqyti6TfqMZ6bsayNKrpJWTxsiU4dQoEDEseutznjPTDx0iI hoN5piQrGCF0HPI9TlTVO6MDMcDEMS+COLsDiaU4Z086BLKr3sNaK2iEK/CWmuPV0LzS 2zJEzE8heWLugGRo7WeR6WJwRNEJZkSNfJ5T/uKxk2R2+HXg/7xS6lMMtn2K5fxYRuXz dqCbRp1TmQI97z765Vt9xYAzNNhgoshWrfSWDQh6LTRpzTY9r0Keuq0v6g6mBOmjPzLJ G4+g== X-Gm-Message-State: AOAM531UAmY8RGnEBZbaIyzxQBNkg3iga+F0P8TRjw2p/KsvQAKS3poa Jz3X9pT3vc4cFVVjKAQB5hyJYYn4P+iDUdJ/19eU1yb9S4E= X-Google-Smtp-Source: ABdhPJxnzUM7TKoipdB4cUeZCusiaI9scagPMsNickWgjOcIw6Ek4IMOxHnOUf3u/4KbbFmqwFiqgAREQ6AxhN3W6xQ= X-Received: by 2002:a19:7d05:: with SMTP id y5mr2809563lfc.159.1623831413720; Wed, 16 Jun 2021 01:16:53 -0700 (PDT) MIME-Version: 1.0 References: <88588b8f-5729-4458-90b1-c602f751e128@www.fastmail.com> <33fd3541-8518-4f98-a258-705f85180ed1@www.fastmail.com> In-Reply-To: <33fd3541-8518-4f98-a258-705f85180ed1@www.fastmail.com> Date: Wed, 16 Jun 2021 10:16:37 +0200 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000970a3a05c4ddb683" Subject: Re: [PHP-DEV] [RFC] New in initializers From: nikita.ppv@gmail.com (Nikita Popov) --000000000000970a3a05c4ddb683 Content-Type: text/plain; charset="UTF-8" On Tue, Jun 15, 2021 at 6:31 PM Larry Garfield wrote: > On Tue, Jun 15, 2021, at 10:06 AM, Nikita Popov wrote: > > On Fri, Jun 11, 2021 at 5:02 PM Larry Garfield > > wrote: > > > > > On Wed, Mar 3, 2021, at 9:03 AM, Nikita Popov wrote: > > > > Hi internals, > > > > > > > > I would like to propose allowing the use of "new" inside various > > > > initializer expressions: > https://wiki.php.net/rfc/new_in_initializers > > > > > > > > In particular, this allows specifying object default values for > > > properties > > > > and parameters, and allows the use of objects as attribute arguments. > > > > > > > > The RFC is narrow in scope in that it only adds support for "new". An > > > > extension to other call kinds should be straightforward though. > > > > > > > > Regards, > > > > Nikita > > > > > > Hi Nikita. What's the status of this RFC? Are you going to bring it > to a > > > vote, or is something else blocking it? > > > > > > > I've just pushed a larger update to the RFC, which limits the places > where > > new is supported. > > > > Supported: > > * Parameter default values (includes promoted properties) > > * Attribute arguments > > * Static variable initializers > > * Global constant initializers > > > > Not supported: > > * Static and non-static property initializers > > * Class constant initializers > > > > I believe the cases that are now supported should be completely > unambiguous > > and uncontroversial. The other cases have evaluation order issues in one > > way or another. This is discussed in > > https://wiki.php.net/rfc/new_in_initializers#unsupported_positions. > > Thanks, Nikita. I would vote for this as is, but I am saddened by the > lack of static property initializers. That's the main use case I am > interested in. (In particular, because sealed classes plus > new-in-static-property would allow for something substantially similar to > tagged unions, just not built on enums, and the latter is not making it > into 8.1 it looks like.) > > Arguments and attributes are enough to justify this RFC on its own, but is > there a way we can resolve the static property question? Right now the RFC > says "these initializers are evaluated lazily the first time a class is > used in a certain way." Can you be more specific about that certain way? > Is there a certain way that would be minimally disruptive? Well, here is a non-exhaustive description of current behavior: * If you access a class constant, only that constant is evaluated. * If you access a static property, all initializers in the class and parent classes are evaluated. * If you instantiate a class, all initializers are evaluated. * Inheriting from a class or calling a static method doesn't evaluate anything. As you can see, the rules are rather ad-hoc. To the user, it's probably not obvious why instantiating an object of a class would require evaluating class constants at that point. The reason is that instantiation requires resolved property defaults, and we happen to evaluate all initializers at once. The options where static properties and class constants are concerned are: 1. Eagerly evaluate initializers on declaration. This is what I tried in an earlier revision of the RFC, and I don't think that approach works. It breaks existing code and has various other unpleasant complications. 2. Precisely specify the current behavior. I don't want to do this either, because the exact places where evaluation happens are something of an implementation detail. If in the future we find it convenient to separate evaluation of non-static properties on object instantiation from evaluation of static properties and class constants (which are not strictly needed at that point), I'd like to retain the liberty to make such a change. 3. Do not specify an evaluation order, beyond that evaluation happens at certain uses of the class. Evaluation order may change across PHP versions. If your code relies on any particular order, your code is broken. Unless I'm missing a fourth option here, option 3 is the only one I would be willing to go for at this time. Also, I think there's a typo in the preceding paragraph about property > initializers. It says "the disciplined invocation of such constructors > from potential parent constructors." Shouldn't that be potential child > constructors? > Yeah, that's right. Fixed! Regards, Nikita --000000000000970a3a05c4ddb683--