[New PHP Features] PHP8 has been released

PHP

Hello, I'm Kashiwagi from Beyond, formerly in charge of ISMS, formerly a programmer, and currently a general handyman with many "former" roles.
PHP 8 was released in November 2020, and since it hadn't been mentioned on the Beyond blog yet, I'm giving it a quick introduction.

First, what is PHP?

It's a well-known server-side scripting language.
Its ease of understanding its specifications and syntax makes it a low-cost language to learn and widely used.
Database connections are also easy, making it accessible even for beginners.
Installation is simple.

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, you might not see as much benefit with web content.
It seems like batch processing in PHP, which has been avoided until now, will become much easier.
However, since many people have already explained JIT in blogs and such, I will omit the details.
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"

This was just a brief introduction to some of the easily accessible features, and
I don't think there were any major changes to the specifications this time around, but
I think there were plenty of things to see.

some upgrades from PHP5 and PHP7 still exist worldwide
it's important to note that

We recommend that you consider upgrading by comparing the sources you currently have with the official sources

If you found this article helpful,please give it a "Like"!
1
Loading...
1 vote, average: 1.00 / 11
1,011
X Facebook Hatena Bookmark pocket

The person who wrote this article

About the author

Hirofumi Kashiwagi

A pseudo-engineer

Date of joining the company: 2010/11/10
Previous experience: Two development companies
Current job: Aspiring engineer
Qualifications: AWS SAA, GCP PCA

I don't really like Kashiwamochi