david.dev


Welcome PHP 8! 🐘

17/02/2021

#php, #php8


A few months ago PHP 8 was released: since a lot of new interesting functions were added, most notably the JIT (just in time) compilation that will make PHP much faster, I knew I would answer to the 🧜‍♀️ and had to try it.

Not only I did, but I moved my blog from Python3/Django 3 (previous NodeJS/Polka) to PHP 8.

Here are some of the new functions in PHP 8:

match: a better version of switch (less verbose, no break needed)

$message = match ($statusCode) {
200, 300 => null,
404 => 'not found',
500 => 'server error',
default => 'unknown status code',
    };

str_contains

if (str_contains('winter is comming', 'winter')) { /* … */ }         

and many more functions that you can check in the official release notes

NodeJS still has a very big ecosystem of NPM packages but I can't think of any web app that you can code in Node but not in PHP 8 ;)

So I did switch from Python/Django 3 to PHP 8. A lot of things are great in Django and it can't be compared with PHP (a language, not a framework) but perhaps I feel like trying something new - PHP is not new to me but PHP 8 certainly is!

PHP is also very rich so you do have (almost) all you need in the core functions. You need an API ? In PHP 8 the JSON extension is always included. So you don't need a REST framework you can just use json_encode and json_decode and you are set.

Porting the code from python (and NodeJS) to PHP 8 was easier than I expected and everything works perfectly. Deployment is a breeze and all is so well integrated. I hope to stick to PHP 8 for a while!