[PHP new feature] PHP8 has been released

table of contents
Hello, I'm Kashiwagi, a former ISMS manager and programmer at Beyond, and currently a juggler with many past experiences.
PHP 8 was released in November 2020, but it hasn't been mentioned on the Beyond blog yet, so I'd like to take this opportunity to introduce it to you.
First, what is PHP?
It goes without saying that it is a server-side scripting language.
Its specifications and grammar are easy to understand, so it has low study costs and is used in a variety of places.
Its ease of database connection, etc., makes it easy for even beginners to implement.
It is also easy to install.
Install it on CentOS7 right away
$ sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm $ sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm $ sudo yum -y install yum-utils $ sudo yum --enablerepo=remi-php80 install php
The installation should be complete, so let's check the version
$ php -v PHP 8.0.0 (cli) (built: Nov 24 2020 17:04:03) ( NTS gcc x86_64 ) Copyright (c) The PHP Group Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
The installation was successful. Installation is as easy as ever
Try out the new features now
JIT
Processing will be faster. However, the benefits may not be as great for web content.
It seems that batch processing in PHP, which has been avoided until now, will be facilitated.
However, since many people have already explained JIT on blogs etc., I will not go into detail here.
I introduced it because it is a key feature.
Named arguments
This is a new feature that allows you to pass arguments by name. This is already familiar in other languages such as Python
// Named arguments function sample01( int $mae = 0, int $ato = 0 ) { var_dump( $mae ); var_dump( $ato ); } // You can specify which arguments sample01( mae: 1, ato: 2 ); // Output result // int(1) // int(2) // You can also do it the other way around sample01( ato: 2, mae: 3 ); // Output result // int(3) // int(2) // You can also do just one of them sample01( ato: 4 ); // Output result // int(0) // int(4)
match expression
This is a new function that allows you to use switch statement-like processing like a ternary operator
$x = 2; $sample02 = match ( $x ) { 1 => '$x is 1', 2 => '$x is 2', default => '$x is anything else', }; var_dump($sample02); // Output result // string(8) "$x is 2"
I've only introduced some of the things that are easy to try out, and
I don't think there were any major changes to the specifications this time, but
I think there was still a lot to see.
you should be aware that there are some features and implementations that are not backward compatible when upgrading from PHP5 or PHP7, which remain in the world
We recommend that you consider upgrading by comparing the sources you currently have with the official sources
1