The DevTeam Alpha News Aggregation service has sourced the following article originally published on SiteGround:
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 every body 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.
I love the new strong typing features in PHP 7. Each release have given us new options and made strong typing PHP code easier and stronger. All the while, the core developers have been sensitive to those who do not want to implement strong typing making all features optional. PHP 7.4 continues this tradition by extending strong typing to class properties. Now type hinting is not limited to method properties and return types, developers can hint the properties in their class as well.
Santa’s bag contains a lot more presents for good PHP developers around the world. So make sure you are prepared. Get to bed early on release night. Don’t forget to leave a glass of milk and some cookies out for Santa, and don’t forget to set out a 100 pound bag of peanuts for his ElePHPants.
PHP 7.4 can be enabled through our PHP Manager or from the Environment Options tab in the SG Optimizer! Make sure you check your website thoroughly after switching to the latest PHP version since some plugins may not be ready for it yet.
Learn more about SiteGround by visiting their website.