Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122653 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 5FB321AD8F6 for ; Sat, 16 Mar 2024 08:32:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1710577982; bh=uAeZNlqCT2AbMUyE90GBfHzDiZBFFdJFRd/ZVrjHOMs=; h=Date:From:To:Subject:In-Reply-To:References:From; b=fPw32k3qe5saGv/seNNV9+pKufBlay8D9B4Kb/QALK8d8rCJo9JTKfAqcvR4jinnP npCTo2ZKHTgbEBvnLh+LTvxvfrn4OvmQAOOFB1AYSGwR9KqGDc6Ow/DY14Zgg1FfB7 HE+pWCImNH2PMRt59xvUw5/bNjYGQWEtS1wfQdpSoqj3SfxIFx8PRGOhdCyyZxm3or E02orcW58ijL2tBTFLemQHY1AwOIM5dT9jB68crHiDbcmUcw+x2xzIenVW8iwshwuy ViGxJZ+fe/YgNq6fehUanSqJ1C3yucGxxmw5biflF/aFIrqWy4zBVt7AUHMPpvVkz/ rs2ngDaub1CUw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 57D17180004 for ; Sat, 16 Mar 2024 08:33:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 16 Mar 2024 08:33:00 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id D08A11380081 for ; Sat, 16 Mar 2024 04:32:41 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Sat, 16 Mar 2024 04:32:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1710577961; x=1710664361; bh=eVVhEo8oKM3qg1nJogzOkvbfRTUnhDkB2j72ZV+kx1Q=; b= lWMVCJ74Y9gvPzvnPA/8dWdSCk7yz8grtdJQaf7/9K5ByljwK3V5i/HUBzRihtIc SWpHYkf7H0UOV/et6MReKUfqVkOV0BkTGjgS9IBH+6//7VUuKiwAI+b6C5K/gGHg mdwfB89+pzoKB7dwi3Cf3eiEKrMsSfvCJLFPTSg/gjaCCeCWZ2u6phpI1L2CCcCU HhM8DwMYnJ3hJPZ8X8C25o4dh7+B7LquSiRpQvUirgvKZWqrsj02MXpVfCV514WQ b28IjVdIkkw62cRneMnDGUm+kjkhoW/d1i/uDPKkBOj8/vS/vAaoM6pfCeC83lRu rhYcTin9wXRwwqLH97ukYA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1710577961; x= 1710664361; bh=eVVhEo8oKM3qg1nJogzOkvbfRTUnhDkB2j72ZV+kx1Q=; b=g JCGK/6VCMoBb6hqsnfKKucCRIIEErEJTz1prfW9/L5niTGa7wK6RCXUklnbgX3Lr 9WIb02IVV385UWG4tZ7zriFzM+yJ+5ahPLuWjCtGN4D9hCKMSFnCQgSWoRIOzBKL u6EU0RoV1reWwBLkPbNGgvKY6Tdw98FgdRoIKUC47wOnVrvZNwGfjTCye9OYma6V f26mkKRv+UP/KRzbfawRtM12pKJ1U32BgEPlfvIzW4WGCJSWf80sz04wq8w/GjYu RpkES1RAXadDeJJeZAc6cQBYjZWkKhyNYYrbG4i1Z1qp7V1SJ736UXoM0ByHhyg5 byHv4zdANg+LLx72LwWPA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrkedtgdduvdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvufgfjghfkfggtgfgsehtqh hmtddtreejnecuhfhrohhmpedftfhofigrnhcuvfhomhhmihhnshculgfkoffuohfrngdf uceoihhmshhophdrphhhphesrhifvggtrdgtohdruhhkqeenucggtffrrghtthgvrhhnpe ehleffteeigfevudetfedugedtudevledugeeugeelheeihfehgfdtkeevvefgleenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehimhhsohhprd hphhhpsehrfigvtgdrtghordhukh X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Sat, 16 Mar 2024 04:32:40 -0400 (EDT) Date: Sat, 16 Mar 2024 08:32:39 +0000 To: internals@lists.php.net Subject: Re: [PHP-DEV] [RFC[ Property accessor hooks, take 2 User-Agent: K-9 Mail for Android In-Reply-To: References: <7eada0fd-39c5-4a89-8c74-80c671801a2d@app.fastmail.com> <1698692e-8eb1-4bfc-a743-375696cd8f1c@rwec.co.uk> <154481e0-5f62-4026-994a-28a644d71527@app.fastmail.com> Message-ID: <46609F15-DD40-4BD2-A78A-16021C3447C8@rwec.co.uk> Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 16 March 2024 00:19:57 GMT, Larry Garfield w= rote: >Well, reading/writing from within a set/get hook is an obvious use case t= o support=2E We cannot do cached properties easily otherwise: > >public string $expensive { > get =3D> $this->expensive ??=3D $this->compute(); > set {=20 > if (strlen($value) < 50) throw new Exception(); > $this->expensive =3D $value; > } >} To play devil's advocate, in an implementation with only virtual propertie= s, this is still perfectly possible, just one declaration longer: private string $_expensive; public string $expensive { get =3D> $this->_expensive ??=3D $this->compute(); set {=20 if (strlen($value) < 50) throw new Exception(); $this->_expensive =3D $value; } } Note that in this version there is an unambiguous way to refer to the raw = value from anywhere else in the class, if you wanted a clearAll() method fo= r instance=2E I can't stress enough that this is where a lot of my thinking comes from: = that backed properties are really the special case, not the default=2E Anyt= hing you can do with a backed property you can do with a virtual one, but t= he opposite will never be true=2E The minimum version of backed properties is basically just sugar for that = - the property is still essentially virtual, but the language declares the = backing property for you, leading to: public string $expensive { get =3D> $field ??=3D $this->compute(); set {=20 if (strlen($value) < 50) throw new Exception(); $field =3D $value; } } I realise now that this isn't actually how the current implementation work= s, but again I wanted to illustrate where I'm coming from: that backed prop= erties are just a convenience, not a different type of property with its ow= n rules=2E > Being the same also makes the language more predictable, which is also a= design goal for this RFC=2E (Hence why "this is the same logic as methods= /__get/other very similar thing" is mentioned several times in the RFC=2E = Consistency in expectations is generally a good thing=2E) I can only speak for myself, but my expectations were based on: a) How __get and __set are used in practice=2E That generally involves rea= ding and writing a private property, of either the same or different name f= rom the public one; and that private property is visible everywhere equally= , no special handling based on the call stack=2E b) What happens if you accidentally cause infinite recursion in a normal f= unction or method, which is that the language eventually hits a stack depth= limit and throws an error=2E So the assertion that the proposal was consistent with expectations surpri= sed me=2E It feels to me like something that will seem surprising to people= when they first encounter it, but useful once they understand the implicat= ions=2E Regards, Rowan Tommins [IMSoP]