Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113606 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 52686 invoked from network); 19 Mar 2021 11:28:31 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Mar 2021 11:28:31 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E96751804DC for ; Fri, 19 Mar 2021 04:23:00 -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-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (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 ; Fri, 19 Mar 2021 04:23:00 -0700 (PDT) Received: by mail-lf1-f52.google.com with SMTP id b83so9414651lfd.11 for ; Fri, 19 Mar 2021 04:23:00 -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=URdflGYT5Sfxe73ZbdGyw3cDqcpVktHTnx1vApAfhPM=; b=EcCOzbsKOvHt2rKr7QzqLN/h1Kebwuj5PoSx+grblZewJhn49X8c8SULKeaDwc1r9w wC/qLLMaSxLps43iixsD/Job1BNFVKPQSPv6kpsipt/Vk5m8aZ8YtdLnPRbLP9PC0Sbl T8bFWtGAV1I9hVLDIvMifKpWXbEsbI6vmozOUS25zhSveEP/QwZP4ThaE5+z7sbYNg1S hUB6LTZsfXb/53Unbw3jq2KquvR0yZf1nuNWd3h11kgrBZ0IYAxfUyZNAf6EzLGATB4q X9lYi1WjLM4v45x2YzWLkai5cSYQw+Vd2ugidhX0rzB2/WbTrlOM8b5D00bIdKF6V7FN 04kw== 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=URdflGYT5Sfxe73ZbdGyw3cDqcpVktHTnx1vApAfhPM=; b=H10ucV0IbcNoDONZ+TqHBYFYj6VrIuy4yuePFmrBTOaOhBSt/C0G0PNlldSMgJkSLY 05hDNHT9YVGNEMx+d8Bc2IWVD9pqlN+1jvt4CHyitGqIjqPF8bnapRhERZw0mMCiyJiW 5nt3nf5rhSbvO58YOlehfXw/tb4fLmDAlSbQDtnUhvCwWY9gh0pfwbZCRfjcVhw6mcia 3FFtiBQzaN4RdGuzpWVwxTS9hgkEsRTe0/jNtfB2v/6zz6uY4j7AIPfs0RjzT7jKmdn9 khUUTC5rQWvLuqanhgPTdX330XkphkivilDeY5PKPC3+1bWyGuRxYLK0pcQdB0g8PHvm K8ow== X-Gm-Message-State: AOAM530l4e8Y0oDQyIhyM597lJqKiHD5aENe5eIgbOctQS+9pdeT/an/ kuS1aazuv4PUA+1tDcGGZBIgTJun0RahFIfR2gU= X-Google-Smtp-Source: ABdhPJzuJXuJCuuX10hqdhNZdPS2v2jwtol9dNXmornYNb4QmFIwBXrlBaHkPmkSRrWRnJwwr9w/mTwyyhjPeErtkfw= X-Received: by 2002:a19:c7d3:: with SMTP id x202mr526455lff.638.1616152978811; Fri, 19 Mar 2021 04:22:58 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 19 Mar 2021 12:22:42 +0100 Message-ID: To: =?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?= Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000346d9205bde1f05b" Subject: Re: [PHP-DEV] [RFC] New in initializers From: nikita.ppv@gmail.com (Nikita Popov) --000000000000346d9205bde1f05b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Mar 3, 2021 at 7:04 PM Alexandru P=C4=83tr=C4=83nescu wrote: > > On Wed, Mar 3, 2021 at 5:49 PM Nikita Popov wrote: > >> 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 consta= nts >> 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 favo= r >> 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 predicta= ble >> behavior once potentially side-effecting expressions are involved (we >> already support side-effecting expressions right now, but less explicitl= y). >> >> > Yes, this is what I was thinking about, to have a clear stated order of > initialization. > Yes, I agree that class constants and static properties should be eagerly > declared when class is declared. > > So the order would be: > - constants and static variables, when reaching the statement that does > the declaration > - class constants and static property, when class is declared, in order o= f > their declaration in the class > - instance property, when class is instantiated, in order of their > declaration in the class, before construct > - parameter defaults and attribute arguments defaults, when > function/method/attribute construct is called, in order of the declared > parameter/arguments. > > That sounds good to me. > Thanks! > Alex > I've updated the RFC (and implementation) to evaluate class constants and static properties at time of class declaration. As such, everything should have a well-defined evaluation order now. However, this also means that this RFC now also contains a backwards-compatibility break: Anything used inside class constant / static property initializers needs to actually be available at the time the class is declared. You can't first declare the class, then declare some additional constants it uses, and then use it. Nikita --000000000000346d9205bde1f05b--