What’s New in PHP 7.1

0
Language

Level

Beginner

Access

Paid

Certificate

Paid

Though not as flashy as the long-in-development 7.0 release, PHP 7.1 nonetheless brings with it a number of useful features, ranging from short array destructuring, to negative string offsets, to improved return types. Come along, as we review what’s new in PHP!

Add your review

Install PHP 7.1

Before we can toy around with the new additions to PHP 7.1, we must first install it. In the past, this was always a pain in the neck to accomplish

however, these days, we only need to pull in Rasmus’ Vagrant image to get up and running as quickly as possible.

Symmetric Array Destructuring

First up, we have symmetric array destructuring: an incredibly confusing term for a simple concept: we can now use the short array syntax to translate (or destructure) any array – both indexed and associative – into a list of variables.

Nullable and Void Types

Nullable and void types are both new to PHP 7.1. Should you desire to, you may now mark a typehint or return type as being nullable, simply by prefixing it with a question mark. This indicates that you expect either the given type, or null. Additionally, the ability to specify a void return type is now available.

Multi-Catch Exception Handling

Often, you’ll find yourself catching and responding to multiple exception types with the exact same logic. In PHP 7.1, however, you may now remove this duplication by separating each exception type with a pipe (catch (ChargeFailed | InsufficientFunds $e)).

Iterables

New to PHP 7.1 is a new iterable pseudo-type. If you’re currently type-hinting array all over the place, think about it: would you be that upset if the user instead passed an object that can be iterated over? Of course not. This new pseudo-type solves that!

User Reviews

0.0 out of 5
0
0
0
0
0
Write a review

There are no reviews yet.

Be the first to review “What’s New in PHP 7.1”

×

    Your Email (required)

    Report this page
    What’s New in PHP 7.1
    What’s New in PHP 7.1
    LiveTalent.org
    Logo