Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115231 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 14796 invoked from network); 30 Jun 2021 09:35:44 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Jun 2021 09:35:44 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C37081804F3 for ; Wed, 30 Jun 2021 02:55:57 -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, 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-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) (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, 30 Jun 2021 02:55:57 -0700 (PDT) Received: by mail-qt1-f182.google.com with SMTP id f20so1015604qtk.10 for ; Wed, 30 Jun 2021 02:55:57 -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:content-transfer-encoding; bh=8ysfvoT5g4QRE9P0ctJncnVPCqpGFhbLn3/dxSSjmhg=; b=txm14pMckPuC1L7qg27APo/kykTn57FfUM0ObB+vLsf2NVtvU5WTqX1FWsdYksVmd6 TSw5XdOL+kg4QanFmU24e84bWJT+NWtI4/4i/FJg2ipoErBMJ+7jqnNnUci4JMmzRDlO ZUOwolSDyWcdtywyZe9Spw/vJgW4yfA6YVqG9Pbh86o/uWUXXKll8cGbq0YqM1oBJZms shj603kGxGiO3eZ9ZFOofmj06qiDug94ZUE3aoYDTIxH5SVi8vAfOZl7ABviuwxjzkMl CJajD9rTofexTMMJg0I76rNMZtMOtma5cRPjUZ87p8StdhHDKpgV4HZadnGLxwDK7jk7 YsOA== 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:content-transfer-encoding; bh=8ysfvoT5g4QRE9P0ctJncnVPCqpGFhbLn3/dxSSjmhg=; b=kgNS6fwY392J/yjRPOU+qw05SEsvBzjn7RfGFZPnF2GRjCD0i8ptzJYGp0D4lGf8SR j2Np8UBrPpWmD+LVEFqbhfRJq6YE8Bjwzo/YlRCbeUr0Hn+5c2OcL2o03UgMB/pJn6il vy28mY6ItLiD2NlSQIUUqjk1Hh/iBX9/wCKX/g02pLh9ED/AYHu+kjuRRh9rkbFk074E LpJHO5J97Q+UNjyODz+VDRjSaYQikVq7qRnU5VUm/vilxMyFU+k/6uHlPWW6Qql5OpTu TlSD3ceiFEgnTForeobVNLIvvgKrw9VhAyDkiYDroeW/WoNpA+xBBPmikrGDsCwCOubF 1XuQ== X-Gm-Message-State: AOAM531VyIgMVzWKMu6d/aGqxk0UM7I/fdHWeWveAZbkeUoBH2+KEVO6 ARh3mdOBz5lQvBx+ruK9zr3YcLLCRLnpk4E7ct4= X-Google-Smtp-Source: ABdhPJw+MreADhiEVy3ViWGna/JhGVGQLo0gqX7U/PR2CyixxS3Dc043m3FXayHAgIYBVLV5BbP7WRztlnWtkmuK6/E= X-Received: by 2002:ac8:7ed9:: with SMTP id x25mr327070qtj.39.1625046955911; Wed, 30 Jun 2021 02:55:55 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 30 Jun 2021 11:55:44 +0200 Message-ID: To: Nikita Popov Cc: Larry Garfield , PHP Internals List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Re: [RFC] Readonly properties From: andre.romcke@gmail.com (=?UTF-8?B?QW5kcsOpIFLDuG1ja2U=?=) > Yes, this is a possible alternative interpretation of the readonly concep= t. The current proposal is closer to how Java final variables work, which n= ever allow reassignment, while your suggestion is closer to C# readonly, wh= ich does allow reassigning in the constructor. > > I went with the current proposal, because it integrates nicely with the i= nitialization concept introduced by typed properties. At the time, we also = had lots of discussions about how typed property initialization should work= , and requiring that all typed properties be initialized by the end of the = constructor was one of the contenders. However, we ultimately decided again= st such an approach, because it does not integrate well with other aspects = of the language. In particular we need to have the ability to initialize an= object while bypassing the constructor, and we don't have the ability to d= etermine initialization statically, so an uninitialized state would have be= en required in any case. > > If we had gone with that alternative initialization model at the time, th= en we would also use the same one for readonly properties. But that's not h= ow things work now. Doing something like this now would require introducing= an entirely new scoping concept. This brings up awkward questions like: Ho= w do you bind a closure to this new "initialization scope"? Closure rebindi= ng is a common way to bypass visibility restrictions. What happens if you w= ant to call a helper method to do the initialization, does that still count= as initialization scope? What if you call $object->__construct() directly,= will that allow changing properties? > > The current proposal tries to provide a simple, absolute guarantee: Once = initialized, the property will never change again. I think that makes the f= eature easy to understand and reason about. Thanks for the detailed explanation, I'm sold! And it seems it can evolve further once complementary features are introduc= ed.