====== PHP RFC: Final Property Promotion ====== * Version: 0.1 * Date: 2025-03-24 * Author: Daniel Scherzer, daniel.e.scherzer@gmail.com * Status: Under Discussion * First Published at: https://wiki.php.net/rfc/final_promotion * Implementation: https://github.com/php/php-src/pull/17861 ===== Introduction ===== When [[rfc:property-hooks]] added property hooks, it also added a mechanism for properties to be declared as ''final''. However, the ''final'' modifier is not currently supported for properties that are created via constructor property promotion. This RFC proposes that ''final'' properties also be allowed in constructor property promotion. The reasoning is basically the same as from the original [[rfc:constructor_promotion]] RFC - reducing boilderplate. ===== Proposal ===== When a constructor parameter is marked with ''final'', it is considered "promoted" and treated like other promoted properties, with the resulting property also being marked as ''final''. Since properties declared as ''final'' do not need an explicit visibility set (defaulting to public), no visibility is required in the promotion if ''final'' is used, though visibility (including asymmetric visibility) and other features (like property hooks) can be used and combined with ''final''. ===== Backward Incompatible Changes ===== None, all prior code that was valid is executed the same As with all RFCs that make code that previously had a compile-time error become valid, this RFC requires updates to static analyzers and IDEs to understand the semantics of constructor parameters marked as final. ===== Proposed PHP Version(s) ===== Next version of PHP (PHP 8.5 or PHP 9.0) ===== Unaffected PHP Functionality ===== Since ''final'' was not valid for property promotion previously, the behavior of existing legal code is unchanged. ===== Proposed Voting Choices ===== Allow ''final'' to be used with property promotion? ===== Patches and Tests ===== https://github.com/php/php-src/pull/17861 ===== Implementation ===== After the project is implemented, this section should contain - the version(s) it was merged into - a link to the git commit(s) - a link to the PHP manual entry for the feature - a link to the language specification section (if any) ===== References ===== * [[rfc:property-hooks]] * [[rfc:constructor_promotion]] * Discussion thread that led to RFC: https://externals.io/message/126475