Santa’s Got a Bag Full of PHP 7.4 Goodies
PHP 7.4 is already available on all SiteGround servers and we have invited our great friend Cal Evans, who is also one of the most admired people in the PHP community, to share which are the best things in the new PHP version.
It’s that time again. Time for Santa to hitch up the ElePHPants that power his sleigh and deliver that present all good developers have been waiting for, the newest release of PHP. I took a quick peek in Santa’s bag and here are my top three features coming in PHP 7.4.
Anonymous functions in PHP are great. Many times though, they are overly verbose for what is needed. If all you need is a single expression you end up writing a lot of code to get that single expression. Now in PHP 7.4, single expression anonymous functions can be written in a single line. The new syntax is clean, and the end result is much more readable code.
Null Coalesce short(er) syntax
One of my favorite additions to PHP 7 was the null coalexce operator. (??) Since its inception, I’ve used it in almost everybody of code I’ve written to ensure that variables have a sane default. Now with PHP 7.4 developers can use an even shorter syntax. Keeping in line with the increment operator, we can now use “??=” to assign a default value to a variable if it is null, but leave it unchanged if it has a value.