Typed Properties in PHP

As mentioned before I’m really looking forward to Typed Properties that will land in PHP 7.4 (now in alpha!). Brent has done a full writeup on ‘m:

In this post we’ll look at the feature in-depth, but first let’s start by summarising the most important points:

  • They are available as of PHP 7.4, which is scheduled to be released in November of 2019
  • They are only available in classes and require an access modifier: public, protected or private; or var
  • All types are allowed, except void and callable

Typed properties in PHP →

💭 As also mentioned before, I’m missing one specific typehint: Foo[].

This typehint would tell PHP that you require a variable to be “an array of Foo‘s”. With the current typehint system that not possible: when requiring the type array, you cannot specify its contents.

And no, the variadic function syntax is not a closing solution workaround for this.

Published by Bramus!

Bramus is a frontend web developer from Belgium, working as a Chrome Developer Relations Engineer at Google. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.