Arrow Functions

Learn about the new features of arrow functions that were introduced in PHP 8.

Arrow functions were actually first introduced in PHP 7.4. However, as many developers do not follow every single release update, it’s important to include coverage of this excellent new feature.

In this lesson, we will learn about arrow functions and their syntax, as well as the advantages and disadvantages compared with anonymous functions.

Generic syntax

Simply put, an arrow function is a shorthand syntax for the traditional anonymous function, much like the ternary operator is a shorthand syntax for if () {} else {}. The generic syntax for an arrow function is shown here:

Get hands-on with 1400+ tech skills courses.