Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113351 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 52270 invoked from network); 3 Mar 2021 15:59:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Mar 2021 15:59:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 381A4180549 for ; Wed, 3 Mar 2021 07:49:59 -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-Virus: No X-Envelope-From: Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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, 3 Mar 2021 07:49:58 -0800 (PST) Received: by mail-lf1-f44.google.com with SMTP id k9so17938882lfo.12 for ; Wed, 03 Mar 2021 07:49:58 -0800 (PST) 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=cSM4sUTb2fZ7GDIq/8F/HNKbPsynQBFw6Y8ZTAeDGXQ=; b=SgRBtWllVI0li3xPFOkTHAGKUSjX0PdAihlAK8074UxsAnNybnGrz2qu5iYNdra46B eN99NDs48fBQOAn8LGzrt/CivUdihgQ4Mi8nOtvY8g16Sy/Lkkrqz8XYszoIxMmI5e6R ++Ij77fbtryoffPPkBtoe75fu38xq2cKWs9TboxbJTyYYLPpzI8gPiEsgaT3O2Pi1o4m y83f/j8EuMw5sn7jjOl7M4YL8K/Kzy+K/ZigQKzeqv/c4Va15K81VjSLzD8TzxDqXCFH UXjAmnnZCgE6kXMwLQ+13+3EyjxqQ1wBwb7UR/TrgidwJmPJNPfkNawL1KrOYZYy+tvg DkJw== 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=cSM4sUTb2fZ7GDIq/8F/HNKbPsynQBFw6Y8ZTAeDGXQ=; b=dRlV6OJ+YFJDiYie9rV8egIyvSIUvTMOBjE2CvoRpbcAtq2ZmSlMjSD32SA4gRo69t RSROAP1gPlzb4SSfFhEi+47y0Dpzr2ObpRzL9lnYRunZGNwo9oRm+pHXxwm2y3EpVjZD 7+8ZAOxU3/oX3p8jPGh0HAHJoCgojJ0sf9h3tT9dh0rtOxpdH6coOdkkQDvnUEkDxOby 12kVFFXmv5jz0m6r3HerlEXuQh5rMiM9TZA/bV5zJaG1LkVbIC6aj8zUSl2itWC/KY05 DitktwnZtUoVT/PKQz5nlgO0F5k2zY+BpXf8iMiOmSOJsoIwNEWDCiNiWlCiSOxmZmVK ERrQ== X-Gm-Message-State: AOAM5307OE1QlMFUVBxM4Fx2wYRjIilZRxDg7wH7sLzFPEbyADdPzmMg cJ6e1EUplG6EENlyyz2MFOnQVTzCAdeW90H7F/c= X-Google-Smtp-Source: ABdhPJz5PlzebWX3oJuxKZFXAdn4QGCXDK9zjH3MNOw7PRLaMmCAucGjvxnWmFxHNTjxMXMctXsX4DhAbmFdRoX5M9A= X-Received: by 2002:a05:6512:3090:: with SMTP id z16mr16414765lfd.44.1614786595775; Wed, 03 Mar 2021 07:49:55 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 3 Mar 2021 16:49:39 +0100 Message-ID: To: =?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?= Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000006deaf305bca3cd97" Subject: Re: [PHP-DEV] [RFC] New in initializers From: nikita.ppv@gmail.com (Nikita Popov) --0000000000006deaf305bca3cd97 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Mar 3, 2021 at 4:28 PM Alexandru P=C4=83tr=C4=83nescu wrote: > Hi, > > This looks very nice and I'm interested in further steps where not only > new can be used :). > > The only thing I think it would be good to improve is to have a > deterministic order for running initialization. > Yes, this can be done at a later point, I guess. But maybe there is > already an order of initialization right now and people would start > replying on it and it would be good to mention it. > Or maybe I didn't understand what this refers to: "this is not guaranteed > behavior, and code should not rely on a specific point of evaluation." > Which particular cases would you like to see specified? There are five cases that have clearly defined behavior, and that I could explicitly specify if desired: * Non-class constants: Are evaluated immediately when declared (i.e. when control flow reaches the declaration). * Attribute arguments: Are evaluated in the order of the arguments. * Parameter defaults: Are evaluated in the order of the parameters. * Non-static property defaults: Are evaluated in order of declaration, with parent properties first. The constructor is run after defaults are evaluated. * Static variables: Are evaluated immediately when declared (i.e. when control flow reaches the declaration). And then there are the two problematic cases: Class constants and static properties. Currently, PHP evaluates these semi-lazily. All class constants and static properties are evaluated at the same time, on first "use" of the class. I would consider this to be something of an implementation detail. That's what I meant by that sentence. Now, if we allow "new" expressions, then I could see an argument in favor of requiring class constant and static property initializers to be evaluated eagerly, i.e. directly after the class has been declared. This would be a (minor) backwards-compatibility break, because invalid constant/property declarations would error out immediately, even if they don't get used. However, I do think that this would be the most predictable behavior once potentially side-effecting expressions are involved (we already support side-effecting expressions right now, but less explicitly). Regards, Nikita Also, in > https://wiki.php.net/rfc/new_in_initializers#evaluation_of_expressions > I think that for the static initialization the text should say "are > evaluated once." instead of "are evaluated once per request." so we are > more general, including CLI cases. > > I'm used with dynamic initialization coming from other languages, learnin= g > it in Java 13-14 years ago, including the clearly defined order of > initialization. > > Regards, > Alex > > > > On Wed, Mar 3, 2021 at 5:04 PM 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 properti= es >> 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 >> > --0000000000006deaf305bca3cd97--