Member-only story

Top new features in PHP 8

Tim Wells
3 min readApr 7, 2021
Photo by Joshua Aragon on Unsplash

PHP 8 is out as the next major update of the PHP programming language. PHP has long been used for building web applications and has over the years had it’s fair share of people that love it and it’s fair share of people that hate it. All in all it’s been a great tool for many including the famous Wordpress content management system that powers a staggering amount of websites across the internet.

So let’s look at the top features of PHP 8.

Named Arguments

Let’s say we want to call a function that takes four arguments, only the first argument is essential, but we want to override the default value of the fourth argument. In previous versions of PHP, this required entering in the values for all arguments prior to the one you want. PHP 8 now allows calling the function and passing arguments by name.

Lets use htmlspecialchars as an example.

htmlspecialchars ( string $string , int $flags = ENT_COMPAT , string|null $encoding = null , bool $double_encode = true ) : string

In PHP 7 to call this and override the final argument would be:

htmlspecialchars($string, ENT_COMPAT, null, false);

Whereas with PHP 8 we can call it like this:

htmlspecialchars($string, double_encode: false);

--

--

Tim Wells
Tim Wells

Written by Tim Wells

Self taught software developer and photographer.

No responses yet