Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113353 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 62001 invoked from network); 3 Mar 2021 18:14:16 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Mar 2021 18:14:16 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5BAA81804C0 for ; Wed, 3 Mar 2021 10:04:49 -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_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (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 10:04:48 -0800 (PST) Received: by mail-ej1-f49.google.com with SMTP id gt32so32429598ejc.6 for ; Wed, 03 Mar 2021 10:04:48 -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=A7usbYniFim3pCVYg1AqKb10TdAdClxDRBBGT3rU080=; b=W64353mSTHnXdI/oz9pbVQB2UNOKWt+VByYnb6ugwvGp5hXhzHhmBBq+cT+Z62MK4Y bT58IlQejUlidyDPrhQKHr4RfGfbsHAaUa1+KvcGUL60eexfCI1Jik53mf4tQpbrVLib S/lN8K9+640zH00JpMAvb+JsBohvfwC9yf3aujPDHgR7QVcAuNA/CCHKQ7nyAn5KJEVP DRH1U013Zekyoflh3XjnnQ8XL5aBsf9HuYiymkKnmsSVUDTjCNRdU4zKdq7DduoANNKX EJkeGQqq/JCr0TI+OSHe44tWk1U+nCWeVKptSE2r6q4CXNv0OpKffrkhw1Njp6HjcG8k lD7A== 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=A7usbYniFim3pCVYg1AqKb10TdAdClxDRBBGT3rU080=; b=it3URpP8kXLZOBcg1hN9VuXUlyKfOajPShh5nBUiQn+7UKv4DcKGrJVPUFE5QI+38f uH164ExI9hl7y0oh3BktFp2hibinpVcFCVKKrdGIG16uOUkyt//KMHC7x8Bzfif0ZrGL CD7nZjtQS+m2PabHbRAr+Rmo5jiic0nd9TYAhMgH4wub1GCZ45ED6JUDJZzzYFhjcMm3 sKaL7C/Ccy//fSYkqvvwfX5twJY2FXr7lB63r2Mf1B4jsaDig0CLDd4nR+gIVZS4vl44 k+AFRLKreFl5K+Okfilft5s0dj+8Xfekf2poQVCG9Rs+aq0sBDz4q6248XvCkPS4tE4h 3SpA== X-Gm-Message-State: AOAM532TguGHCT6ZQcsseXm9GqSwurUjz7TOHQtTr4R5f1sYFC74wIt8 CtV4OA29zSGbEu+QrZUr73Fv5OjN+YZTM/5tUhM= X-Google-Smtp-Source: ABdhPJzM0eZK+gYaS/s0GYwu0ripd/593m0d4EE3mNknDksSTAJdKgPkaMfCjJbJieI0/OjhsNACVMH25BuqDHKLbzU= X-Received: by 2002:a17:906:3856:: with SMTP id w22mr39327ejc.77.1614794685383; Wed, 03 Mar 2021 10:04:45 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 3 Mar 2021 20:04:28 +0200 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000009b8b8e05bca5aff0" Subject: Re: [PHP-DEV] [RFC] New in initializers From: drealecs@gmail.com (=?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?=) --0000000000009b8b8e05bca5aff0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 guarantee= d >> 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. whe= n > 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 constan= ts > and static properties are evaluated at the same time, on first "use" of t= he > 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 predictab= le > behavior once potentially side-effecting expressions are involved (we > already support side-effecting expressions right now, but less explicitly= ). > > 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 of 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 --0000000000009b8b8e05bca5aff0--