DEV Community

Brent Roose
Brent Roose

Posted on • Originally published at stitcher.io

Short closures in PHP 7.4

Short closures are a way of writing cleaner short functions in PHP:

// A collection of Post objects
$posts = [/* … */];

$ids = array_map(fn($post) => $post->id, $posts);

You can read all about them here: https://stitcher.io/blog/short-closures-in-php

Top comments (1)

Collapse
 
sergey_telpuk profile image
Sergey Telpuk

As for me It's a great change, but It'd better use construct like ()=> - it's shorter