What’s new in the upcoming PHP 7.4?

Written by Bram.us - - Aggregated on Wednesday January 9, 2019
Tags: elsewhere, link, rfc

Good overview by Brendt on the new features that will be landing in PHP 7.4, which is due somewhere December 2019.

I’m especially looking forward to Typed properties. One thing I personally find missing though is how to typehint the contents for arrays — e.g. “I’d like an array of Foo‘s”.

The addition of a [] suffix on the type – like Java has – could potentially solve this. In the mean time you can resort to hackery like this (src):

// Definition
class ArrayOfFoo extends \ArrayObject {
    public function offsetSet($key, $val) {
        if ($val instanceof Foo) {
            return parent::offsetSet($key, $val);
        throw new \InvalidArgumentException('Value must be a Foo');

// Usage
function workWithFoo(ArrayOfFoo $foos) {
    foreach ($foos as $foo) {
        // etc.

New in PHP 7.4 →

« Proficent - Cal Evans

murze.be - Using GraphQL with Laravel and Vue »