Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122583 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 85F7D1AD8F6 for ; Fri, 8 Mar 2024 15:53:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1709913223; bh=8oe9YZxpkZr0oIFB0SXavl0aeo0pkWOl4uOvGK14mlU=; h=In-Reply-To:References:Date:From:To:Subject:From; b=AClgeu+vovi1RsWXUeE+bG4XGzdbKlUFGCizX9FZrMnOpadanTUeyQ80GPX8B4NUK QeLNwc/h1B504JYYQIR9GchbMc014C4NFEFtg2wBIQcvYX8VEF0E5b5qIjQoOz598p Y5wSA+iJ5LZwTq/ky4P+C3BaHATV1eP34xbmY0850cRIjEVmxOI+sl92w+egkokL/u Uet7Lnjv5cLQblpSlBNUi70ISiJ1eAaGL0YZqvFWpkXq9dqmKqdAHDiNScV10wkS7R WGIGTDURmPePUC32Vz//TrVIHXU9PAJtKQMSP358qAnZ01f6N4jiLGmmUswn4rra8a wel3oJ72UWaZA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D1A82180061 for ; Fri, 8 Mar 2024 15:53:42 +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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (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 ; Fri, 8 Mar 2024 15:53:42 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 756D55C004A for ; Fri, 8 Mar 2024 10:53:27 -0500 (EST) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Fri, 08 Mar 2024 10:53:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc: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=1709913207; x= 1709999607; bh=y6rOD9gsHwXpCbW2uIwJT4hNaFnw6DOhylsDB4rhQAA=; b=D H0Fe45zATFr5PkclBPORzmbbMabGbfS+5zRWhkRV5u+FXj2x8kCNn6vCKUbAxvXq X1vv/dOYQd0ZFM4gmZqa2NGNrGWY7b3dRQjKc6TVSWzjWixArLpOGnRdiLRk5r4H Uk3uWo2ngzEZ0osMw38GBWjGnSr32QA3ZvL4Xd14RGIYADYxbVPEvcrPbqWjwnuW mvDSvEbJXQLpnleELE83duBCO8ZfhG/i946s+UtcQNVnXBGSYu0T3X/x1KHy+8O5 XmfnQavTI8vSSZI75P/Np2p+hq313KC9r2ETMzxytLIQT6xG+ApFKpdz3ddOMkxH pNXP5zb1eZwMN2NB6wCoQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1709913207; x=1709999607; bh=y6rOD9gsHwXpCbW2uIwJT4hNaFnw 6DOhylsDB4rhQAA=; b=BgJdRKQsyIdiECo10z8YExhz+XZFHlQdj74t1O4yE1in O0EQXi94QLnicKHTtQBJgXhsJ2z8D2CRFoGBd8v/fG/KI2SbadbbWQkw7AUig7AY 7uktvNT+qUjIvlF6dIi8lYL0qgzx36XJ2IRULE3RXgf3snFhx+wi8VPbN7FuAzJj +xyHSV60QAwpOYiF9KaiNsv2tkLec6fsF0QiqekefsTOIC+8pLvESo8mysZmhtcH CrU2tF+qnglMgZReHfaet9KERf98Egs0uowiZdpN4niIa7jyR6ZrJEWSJA7KQFdn eRp8hHAG6tSS5ND4jMUwvXU1eMP339Hq3gSsynIP7Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrieehgdekudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgrrhhr hicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh eqnecuggftrfgrthhtvghrnhepveehhedvveejledvvefgleevffdtjeekledvkeegheff gfeivdejhffhledtudetnecuffhomhgrihhnpehphhhprdhnvghtnecuvehluhhsthgvrh fuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgv lhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 3193E1700093; Fri, 8 Mar 2024 10:53:27 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-251-g8332da0bf6-fm-20240305.001-g8332da0b Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: In-Reply-To: References: Date: Fri, 08 Mar 2024 15:53:06 +0000 To: "php internals" Subject: Re: [PHP-DEV] [RFC[ Property accessor hooks, take 2 Content-Type: text/plain From: larry@garfieldtech.com ("Larry Garfield") Hi folks. Based on earlier discussions, we've made a number of changes to the RFC that should address some of the concerns people raised. We also had some very fruitful discussions off-list with several developers from the Foundation, which led to what we feel are some solid improvements. https://wiki.php.net/rfc/property-hooks Smaller changes: 1. We've added a PropertyHookType enum for use in reflection, which lets us get rid of a possible exception. 2. get_mangled_object_vars()'s behavior is now defined to be the same as an array, ie, skip hooks. 3. A final property with a final hook is no longer an error. It's just silently redundant, like for methods. 5. Made explict what happens with recursive hook calls and method calls from a hook. The behavior here is the same as for __get/__set. 6. Made support for #[\Override] explicit. 7. Added an FAQ regarding the property-centric approach rather than method-centric approach. 8. Clarified that the parent::$foo::get() syntax works on a parent property regardless of whether it has hooks. 9. Clarified that untyped properties are supported. (Though, it's 2024, please don't use untyped properties.) 10. Clarified that interface properties cannot specify a wider write-type, for simplicity. That could be considered as a future add-on with no BC breaks. 11. Provided an explanation of how to interpret the parent-hook access syntax. 12. Added an FAQ item explaining why a 'virtual' keyword is not feasible. Larger changes: 0. As noted a while ago, $field has been removed. 1. I've added an FAQ question regarding the parent::$foo::get() syntax, and why it is. 2. The $foo => expression shorthand has been removed. The legal shorthands are now: public string $foo { get => evaluates to a value; set => assigns this value; } 3. The set shorthand (with => ) now means "write this value instead". The non-shorthand version (set { } ) is always return void, so you have to assign the value yourself but you get more flexibility. Having updated the examples accordingly, I think this is actually a really nice and intuitive trade-off, as it makes the common transformation and validation cases (eg, in constructor promotion) even easier to follow with no redundancy. 4. On a set hook, the user may specify both a type and name, or neither. (That is, set {} or set (Foo $newFoo). If not specified, it defaults to the type of the property and $value, as before. 5. I restructured how the content in 2, 3, 4 is presented and moved some stuff around so that it flows more logically (I think). 6. The restrictions around references have been softened. Specifically, references are only disallowed if a backed property has a set hook. If it has only a get, or if it's a virtual property, references are allowed. We also added a future-scope section on a possible way to support assigning by reference in the future, if there is sufficient need. 7. Interfaces may now require a &get hook, or just 'get'. A class may use a &get hook on a 'get' interface declaration. This is the same logic as already exists for methods; we're just copying it. Hopefully the above changes should resolve most outstanding concerns. I do think the updated shorthand handling is better overall, so I'm happy with it. There also seems to be little consensus so far on naming this thing hooks vs accessors. Absent a consensus, we'll probably stick with hooks to avoid the effort of renaming all the things. Thank you everyone for the feedback so far, and if you still have some, please say so. (Even if it's just to say that you're happy with the RFC now so we feel more comfortable bringing it to a vote.) --Larry Garfield