Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108713 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 79228 invoked from network); 21 Feb 2020 12:13:44 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Feb 2020 12:13:44 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 50A29180210 for ; Fri, 21 Feb 2020 02:30:05 -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=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-ua1-f54.google.com (mail-ua1-f54.google.com [209.85.222.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 ; Fri, 21 Feb 2020 02:30:04 -0800 (PST) Received: by mail-ua1-f54.google.com with SMTP id l6so463304uap.13 for ; Fri, 21 Feb 2020 02:30:04 -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=o8S3wkVpeyBPXhAyiPhysIsm9WskHL+UsyY978oul54=; b=khJrG1RZg7L2JbPckWPZfCyrx2Q2v/ycP77lTgWLaSOQjbT94HvrmK/cmR2nYpnih6 rsNv0jjag3Ty+7iGh43YMkjwB+ry5seV6Vx3He7+uW8nA3lgjoPgSBHIH3rMxTYE56U6 wlrZ965oeth/y2jau5E1qOe9z/bjThAhNA0wf4pNxAy9jBqOA+BP1STiadYMN4qUf1FS gJBmzMaAxypSmnxpWM2RP/C3zwRtRDXHqbWroKL82KtS9juPdbqXjegAi/J2lbQZV4Vt XP8Zzu/iwXjoiiitl78AKf3SxHIpXMEUT8ViN5F/4TRmR1y82iz1Uk+T2WX2oEMlX0Oc yJaA== 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=o8S3wkVpeyBPXhAyiPhysIsm9WskHL+UsyY978oul54=; b=IpuItB2XVw68Jvk78MFSpfE4Yw1AripYg40d3xKed5iZDhfyEqSys2JpZG+fDJfCse fuNyI9Y5JMJ9zeRy9MPygQuJupf3qmrRZIdoozLYlXxurg2jK34CJuBx3KSWo8YfAk74 Ik6z3oF+/O9u1VaCXRaWOE84mo/gb2B6GtDSkbwoQ3WQ/WVjl3AqANw/bP6eZcrwnjKw yG4hQ+Alqq4Nkt86/3/oZhceqftSlMbsjJDSh5BZVBzU+GC+JyV7UByHgIsLzC3wG3ik LOlFcLaltCCmXFg7oE0KOs1c9iAYRRTZghUCYgnhhOL8UalglQG9k4jFC+tLJukwLPT6 FaUg== X-Gm-Message-State: APjAAAX8sR0a+4TZFZ8HwRNLH1YIO5pJHchP1BA2xqnt5Jnm850O4Rft ulyXhSXSoNcwoqDbiC7xBAnQdI7367mTX0W1RQA= X-Google-Smtp-Source: APXvYqw/s/mwUEsUSvVw9z39HG2XEhgsyq5N1h3Udc8TGPyReCECfnAHXP+BCSaoqvh3Aga/m1HABFsfcXvFZdWx9SI= X-Received: by 2002:ab0:6017:: with SMTP id j23mr18699544ual.3.1582281003197; Fri, 21 Feb 2020 02:30:03 -0800 (PST) MIME-Version: 1.0 References: <8545d15e-ddd5-42be-8405-09697a077234@www.fastmail.com> In-Reply-To: <8545d15e-ddd5-42be-8405-09697a077234@www.fastmail.com> Date: Fri, 21 Feb 2020 11:29:52 +0100 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000216aa7059f1381cf" Subject: Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties From: kocsismate90@gmail.com (=?UTF-8?B?TcOhdMOpIEtvY3Npcw==?=) --000000000000216aa7059f1381cf Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > > Yeah, I'm definitely thinking in relation to the earlier discussion, sinc= e > I think they're all inter-related. (This, property accessors, and consta= nt > expressions.) > The biggest question is whether it's worth to support both readonly properties and property accessors. My answer is clear yes, because there are many-many ways to mess with private or protected properties without and public setters from the outside - in which case property accessors couldn't help much. I collected some examples I know of: https://3v4l.org/Ta4PM Please note that the first two examples also apply to private properties, while the last one only applies to protected ones. > As Nikita notes above, a read-only property with a default value is... > basically a constant already. So that's not really useful. > I agree that they are not very useful, however I wouldn't restrict their usage. Mainly because there are probably some legitimate use-cases, but I also think it would be advantageous to be consistent with the other languages in this case. > For defined-later readonly properties, I'm not sure how the earlier point > about reading an unintialized property isn't valid. Currently: > > class Foo { > public string $bar; > } > > $f =3D new Foo(); > print $f->bar; // this throws a TypeError. > > I would expect the exact same behavior if $bar were marked > readonly/locked/whatever. Are you saying that's not the case? > Sorry if I didn't exactly get the question/example, but what I can tell you is that currently an Error exception is thrown with the "Typed property Foo::$bar must not be accessed before initialization" message, and it would be the case with my patch as well since it doesn't affect the reading side. The situation is the same when it comes to unsetting uninitialized typed properties. Currently, these properties can be unset with no problem (and the __get(), __set() etc. magic methods are then invoked when accessing them), and the same would happen with my patch. > If we could address the performance impact, that would give us much more > functionality-for-the-buck, including an equivalent of read-only properti= es > including potentially lazy initialization. Or derive-on-demand behavior > would also be a big increase in functionality. > > It's not that I don't see a value to this RFC; I actually have a few > places in my own code where I could use it. It's that I see it as being = of > fairly narrow use, so I'm trying to figure out how to increase it so that > the net-win is worth it. > The reason why I brought up this RFC is that I'd really like to add first-class support for immutable objects, and it seemed to be a good idea to first go for readonly properties. This way, the scope of an immutable object RFC gets smaller, while it's possible to only have readonly properties alone. Regards, M=C3=A1t=C3=A9 --000000000000216aa7059f1381cf--