[PHP new feature] PHP8 has been released
table of contents
Hello, I'm Kashiwagi, a former ISMS manager at Beyond, a former programmer, and a current miscellaneous worker.
PHP8 was released in November 2020, and since it hasn't been mentioned yet on Beyond Blog, I'd like to introduce it here.
First, what is PHP?
without saying that it is a server-side scripting language.The
specifications and syntax are easy to understand, so the study cost is low and it is used in many places.
It has the advantage of being easy to connect to the database, so even beginners can implement it without hesitation.
Installation is also easy.
Install it on CentOS7 immediately
$ 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
Since the installation should be completed, 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
It was installed successfully. Installation remains easy.
Try out new features right away
JIT
Processing will be faster. However, you may not be able to get that much benefit from web content.
Batch processing using PHP, which has been avoided until now, seems to be gaining momentum.
However, it seems that many people have explained JIT itself on blogs, etc., so I will not go into details.
I introduced it because it is a featured feature.
named argument
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 argument sample01( mae: 1, ato: 2 ); // Output result // int(1) // int(2) // You can do the opposite sample01( ato: 2, mae: 3 ); // Output result // int(3) // int( 2) // Only one can be used sample01( ato: 4 ); // Output result // int(0) // int(4)
match expression
This is a new feature that allows processing like a switch statement to be used 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'm just introducing things that you can easily try out,
so I don't think there were any major changes to the specifications this time, but
I think there was a lot to see.
please 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 source you currently have with the official source.