Re: [RFC] [Discussion] Final promoted properties
| From: | Ben Ramsey | Date: | Wed, 26 Mar 2025 00:24:50 +0000 |
| Subject: | Re: [RFC] [Discussion] Final promoted properties | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-126952@lists.php.net to get a copy of this message | ||
On 3/24/25 13:33, Daniel Scherzer wrote:
Attachment: [application/pgp-signature] OpenPGP digital signature OpenPGP_signature.asc
Hi internals, I'd like to start the discussion for a new RFC about allowing final promoted properties. You can see some preliminary discussion at < https://externals.io/message/126475>, but this is now an official RFC. * RFC: https://wiki.php.net/rfc/final_promotion * Implementation: https://github.com/php/php-src/pull/17861 --DanielFrom the RFC:
Since properties declared asMy first thought was that it feels weird to define a promoted property without a visibility modifier, but I didn't realize that this is valid in PHP 8.4:finaldo not need an explicit visibility set (defaulting to public), no visibility is required in the promotion iffinalis used, though visibility (including asymmetric visibility) and other features (like property hooks) can be used and combined withfinal.
class Foo
{
final string $foo = 'This is a foo';
}
var_dump(new Foo()->foo);
So, if that's valid, then I don't have any objections following the same pattern with promoted properties.
I find it interesting that you can still declare a class property with the var keyword, but you can't use final with var, and you can't use var to promote properties. That's probably for the best. :-)
Cheers,
Ben
Attachment: [application/pgp-signature] OpenPGP digital signature OpenPGP_signature.asc