Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Laravel News:
Typed Properties Coming to PHP 7.4
Oct 02, 2018 @ 16:49:02

On the Laravel News site, there's a post talking about a feature that's coming in PHP 7.4: typed properties. It covers some of the basics of what they are and how they can help improve your code.

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.

The post quotes the purpose of the feature from the RFC and provides an example of how most developers ensure property type safety now: via getters and setters. They then show a refactored version of this with typed properties, making for a much shorter class definition. They also include a code snippet showing all of the possible types you can use with the typed property functionality. They finish the post with a few of their own thoughts about string typing versus weak typing in PHP and link to the pull request that's in progress to implement the feature.

tagged: typed properties feature language php74

Link: https://laravel-news.com/php7-typed-properties

Trending Topics: