Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122530 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 41DE01AD8F6 for ; Tue, 27 Feb 2024 23:53:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1709078020; bh=gXTbR04kwW8DjsF5rY3z/5FwtHH72IMaPLJrtMe4Udc=; h=In-Reply-To:References:Date:From:To:Subject:From; b=f9vX6b3JRxANdSVaWvgoq/8+CMiPaKco+sVtraxjiNbZFJB+DIl3NfmME9S+IkJzC AI4OmfwwMaNGiAlR+FbEJHy+lioNaLQdRlgufojPitH6h8br6sk9nlrShlxzCJdnRO apBjsAhUXnKwgEfw9+w713ZJfq5vsPwKYs2uoCPLXAa0bB/f4M/DID/0LLFxHnxC5y VaGvKs/2IX673gy4U+UgU1fOk3C4jXYQLJ4QxtkiGgJYqiewxpKojldYf9Ow6+3FEY Ah0EYef90lffPlUcbcoLxmRkV1RophDlBLRv4rTdxU/xIakaR6vIJ0+mmh/Ra78FPu gp8XBkdz4IZ5w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BE1351831C4 for ; Tue, 27 Feb 2024 23:53:39 +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.9 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 27 Feb 2024 23:53:38 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 7215D3200B0F for ; Tue, 27 Feb 2024 18:53:29 -0500 (EST) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Tue, 27 Feb 2024 18:53:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; 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=1709078008; x=1709164408; bh=5UVjsv+DgIcw/xJBYjqx4 +iyS9cuov/AzpG+MMeoxOg=; b=F2S+QLIraUCVdlnNAFEf6/4Q43IgAq0Bc6p9k 20XU1QlLcLX7Y+JfcNYANzuwWbCxoTduDzxF1Q4mWcPKM75g5ZsNZB7DSTNElGgW AMD+iVms2v0IlZL3rG70Ne92DxsAvIBmrms5RAMcnmc5ozpxkABx2mEXW8lJnufh WCYpFlMxALIH9814kEyjFpHpnefnIDoquoa2cnT3yLLsuNmM0E8aCj0IpKr8U58D fJQwfqhucDG7s9k90ILF21+pNnu6RcP5ysMAU4mE475MbIQyeZXypBjmBoZW6i5t qIreLNx8cfhBUT6WER7YeJYjm/0mc73SHX0ZVLcbg9t+QTLiA== 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=1709078008; x= 1709164408; bh=5UVjsv+DgIcw/xJBYjqx4+iyS9cuov/AzpG+MMeoxOg=; b=h 2W631sPdQ3iAKHxoDfoO6kGeDT82Z5OlDUe3FvLXxERn62dJwiZ6XYZ6VKn5Jc8m FgS5AWF58J1u8y25EzEUtk36cQ3s/8ykC5pP8wVxT7dVdcCYx6h4b/tyXUzq7pqT xdT8WQaVYy1zS9tv4b965FGklZKPRaaidQ6i3AjbkUEo6MjP8PgZRNMF+uzDTlS5 mJlAupo5t1alPB/Q733jsS3w5oPHgIO685f+gklQ2VOw2t9NSirnJy/9Or2VRZHr KgYKhs9vy2Ijsx4PQrhnZ/tkZkY96CMVu+4Qdfk2eiDTasahVjll9lV8vaJIO3PU mgwP4PSEXwE+CKYa0R2dA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrgeeigdduhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeffffffjeffudfggeevvdeitdetvdfgjefffeffjeel feejteevheeghffhvdfgleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id B9AD61700093; Tue, 27 Feb 2024 18:53:28 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-182-gaab6630818-fm-20240222.002-gaab66308 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: <40d811c5-43b6-4019-8428-b060ab4282d6@app.fastmail.com> In-Reply-To: References: Date: Tue, 27 Feb 2024 23:53:07 +0000 To: "php internals" Subject: Re: [PHP-DEV] [RFC[ Property accessor hooks, take 2 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Tue, Feb 27, 2024, at 8:51 PM, Benjamin Au=C3=9Fenhofer wrote: > thank you for this proposal. there are some points i'd like to make=20 > into this discussion: > > * Thank you for the removal of $field, it was non-idomatic from a PHP = POV. > > * I would prefer that the short syntax $foo =3D> null; be voted upon=20 > separately. Personally I think it could be confusing and is too close=20 > to a regular assignment for default value and I prefer not to have it=20 > and keep the rest of the RFC. See my long reply to Rowan just now, where I go into this. > * The magic of detecting if a property is virtual or backed is - like=20 > Rowan said - subtle. I would also prefer this to be managed via an=20 > explicit mechanism, by for example keywording the property as=20 > "virtual", instead of the implicit way with the parsing based detectio= n. See my long reply to Rowan just now, where I go into this. > * As Doctrine project maintainer, we have had some troubles supporting=20 > read only properties for proxies. I would have hoped that with hooks I=20 > can overwrite a readonly property and "hook" into it instead by=20 > defining a getter, but "no setter". From my read of the RFC this would=20 > not be allowed and throws a compile time error. Could you maybe clarif= y=20 > why at least this special case is not possible? I didn't immediately=20 > get it from the RFC section on readonly as it only speaks about the=20 > problems in abstract. Once again, readonly properties were designed sloppily without considera= tion of how they would interact with other features. Full asymmetric vi= sibility would have been much better suited to what you describe, but th= at was rejected. (If hooks pass, we are considering taking a second att= empt at aviz. Haven't decided yet.) As for details, consider this technically legal (if ill-advised) code: public DateTimeImmutable $now { get { return new DateTimeImmutable(); } } If that property is non-readonly, then while that may be weird, it's not= really unexpected. There's no guarantee a property won't change value = from one access to the next. UNLESS that property is readonly. But if = it's readonly, what the heck does the above code do? It would be return= ing a different value on every request, so it violates one of the constr= aints on readonly. The hook can do arbitrary logic, which means there's= really no way for the engine to detect at compile time "wait, you're do= ing something dynamic." (That would be an extreme amount of work unless= PHP was pure-by-default, which it is not.) =20 For inheritance, this is the same reasoning for why a property cannot ha= ve the readonly marker removed in a child class. It breaks one of the e= xpected constraints of the property, even if not the type per se. (So i= t's kinda a Liskov issue.) =20 This is true regardless of whether the property is virtual or not. Virt= ual properties just have the extra complication of "when you try to set = it, there's an if (is_uninitialized()) check in the engine. What does th= at even mean when there's no backing property??" There's one carve out that might be supportable, which is just a set hoo= k on a readonly property. That MIGHT be able to work around readonly's = flaws by making sure the set hook calls parent::$foo::set($value), to en= sure the actual write happens in the parent (since readonly is private-s= et, not protected-set). Ilija tells me that could be tricky to do, howe= ver, so we'd rather punt on that for now. Follow-up RFCs (even this ver= sion) could flesh out that edge case alone without impacting the rest of= the design. --Larry Garfield