Typed Properties Coming to PHP 7.4

The Typed Properties 2.0 RFC was accepted with a vote of 70 in favor and one no vote. A 2/3 majority is required because typed properties is a language change. The typed property change is a PHP 7.4 proposal. With the introduction of scalar types and return types, PHP 7 greatly increased the power of PHPs type system. However, it is currently not possible to declare types for class properties, forcing developers to use getter and setter methods instead to enforce type contracts. This requires unnecessary boilerplate, makes usage less ergonomic and hurts performance. This RFC resolves this issue by introducing support for first-class property type declarations. The RFC provides an example where the goal is to enforce type-safety: With the new accepted RFC, that code could be functionally equivalent as follows without sacrificing type safety: Finally, heres an example of all the valid types supported in runtime-enforced annotations for typed properties:

Read Full Article at https://laravel-news.com/php7-typed-properties

Tags: , , , , , , , , , , , , , ,