Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113376 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 63389 invoked from network); 4 Mar 2021 14:03:06 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Mar 2021 14:03:06 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CA269180504 for ; Thu, 4 Mar 2021 05:53:48 -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-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 ; Thu, 4 Mar 2021 05:53:48 -0800 (PST) Received: by mail-lf1-f54.google.com with SMTP id z11so43243873lfb.9 for ; Thu, 04 Mar 2021 05:53: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=/z/CCgUp7hGW/KEF6Pfw7e1ERDJ6QG2dGg0iX8SW9Rs=; b=S8AxMQzqf7tGjr1NtNv1j2on/riZq3vwsRt834PvGvlvUi4eHIU/f+WO+PTaUFU1KB pnf61PK99MlZcWAgMrOPaXIumLZTgP4syTEUIZeQpMNCQKbhFDFZYjHCToXcJ2dz6qhV mX/BrDqfRYiWyzmV9jsQQuNRZo5yJGswdSFOiBrSk/c17Mr/IWjDqqReHnCxSEpxsFM7 xDb3eyFLQV6MbC+LQf+6i6+jhM54OvhQL3hVKg6gKTmdNF6yF0YxM7V+RtIst2k9Tc7H UszufX0q1X11b2cMba3AVcGW4jMouZe6e2ZlN/8CUoyC27sJANipCHQ14jKtP1I7ASFP H15A== 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=/z/CCgUp7hGW/KEF6Pfw7e1ERDJ6QG2dGg0iX8SW9Rs=; b=TovGNNHf+4a0rH1uGLfWcIM2iVy2IHOy4iWcR7z37yE/S+pg/GcNMrVKuvj73jJtMS nfSVd7XNMWhw+Wtxg7rXMwTOeJrUOMBYtNXJ0tmHo9P8ILAGcXLLqL/cS35rw/38QguB ITqoU6b86Yozak4FFPotOtL3XwVzC/wROIn8r16OscddsgpTfPyNrt3t77Q1Kf3eEmLd OOhu0DhPGdyAB9z5fpZBI2q1aDUB3VGVA1xUYJ1eZYP8Rsre56GTuX2CrLLQzy7CKEiZ HkOTon5tCPYoQORRdgNy55f7+uds6K8Hc/i8k3ZodelxP3uBDkRST8fmnXG72jRSMN9a 6LEA== X-Gm-Message-State: AOAM533JA+u9wuhzbXoVa7Z8XGzLt+naFXKsGjTKfM9O/3In4yCf9YAP 2ymfLlyLaksneM+TIY1XQv2eVZkl+Qhla0IEv44= X-Google-Smtp-Source: ABdhPJyGN55Svmeb1MrLIwvtQRsNj8CA4immJOdlwxvSzRJTEH0OGXv68knMM88OsRh1ZVtQP9sM10eMWlYljS62Qrw= X-Received: by 2002:a05:6512:3090:: with SMTP id z16mr2521898lfd.44.1614866026567; Thu, 04 Mar 2021 05:53:46 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 4 Mar 2021 14:53:30 +0100 Message-ID: To: =?UTF-8?Q?Micha=C5=82_Marcin_Brzuchalski?= Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000df9cd905bcb64b92" Subject: Re: [PHP-DEV] [RFC] New in initializers From: nikita.ppv@gmail.com (Nikita Popov) --000000000000df9cd905bcb64b92 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Mar 4, 2021 at 6:21 AM Micha=C5=82 Marcin Brzuchalski < michal.brzuchalski@gmail.com> wrote: > Hi Nikita, > > =C5=9Br., 3 mar 2021, 16:04 u=C5=BCytkownik Nikita Popov > napisa=C5=82: > >> 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. >> > > The reflection mechanism for properties, constants and parameters is not > described in RFC but I do believe it should for constants part. Correct m= e > if I'm wrong there. > > The reflection for ReflectionProperty::getDefaultValue the same for > ReflectionParameter is similar and I get that it possibly should evaluate > the value on each call. But what about constants which by their nature > don't change? > Does that mean that each time ReflectionClass::getConstant is called the > value is already evaluated and the return value always refer to the same > object instance. Is that right? I guess it is. > > IMO it deserves to be described in the RFC. > > In general I love the proposal was especially thinking of it for static > variables. > > Cheers, > Micha=C5=82 Marcin Brzuchalski > I've added a section that describes reflection methods. It works exactly as you say. There is one interesting case though: How should ReflectionObject::newInstanceWithoutConstructor() work? In the current implementation, it will still evaluate the property defaults, including new expressions. This makes sense to me, but I can also see an argument that this method should not evaluate them -- however, in that case I believe it should not initialize any properties at all (leave them in "uninitialized" state). Populating property default values depending on what kind of expression they contain seems like a no-go to me. @Ben Ramsey: Yes, it's possible to use nested new. Generally, all supported constant expressions can be freely combined. Regards, Nikita --000000000000df9cd905bcb64b92--