[Osaka/Yokohama] Looking for infrastructure/server side engineers!

[Osaka/Yokohama] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

【PHP新機能】PHP8 が リリースされました

PHP

こんにちは、ビヨンドの 元 ISMS 担当、元プログラマ、とたくさん元がつく現雑用柏木です。
2020年11月に PHP8がリリースされ、まだビヨンドブログでは触れられていなかったので滑り込み紹介します。

まず PHP とは

言わずと知れた、サーバサイドのスクリプト言語です
仕様や文法の理解のしやすさから、スタディコストが安くいろいろなところで利用されている言語になります。
データベースの接続等も容易で初心者の方でも迷わずに実装できる利点があります。
インストールも簡単です。

早速 CentOS7 に インストール

$ 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

インストールが完了しているはずなので、バージョンを確認してみます。

$ 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

無事インストールされました。インストールは相変わらず簡単ですね。

早速新機能をいろいろ試す

JIT

処理が早くなります。ただ、WEBコンテンツではその恩恵をそこまで得られないかもしれません。
いままで敬遠されていた、PHPでのバッチ処理化がはかどりそうですね。
ただ、JITの説明自体はたくさんの方々がブログ等で説明していただいているようですので詳しくは割愛します。
目玉機能なので紹介しました。

名前付き引数

引数を名前で渡せる新機能です。python 等、他の言語ではすでにおなじみですね。

// 名前付き引数
function sample01( int $mae = 0, int $ato = 0  ) {
        var_dump( $mae );
        var_dump( $ato );
}

// どの引数か指定できる
sample01( mae: 1, ato: 2 );
// 出力結果
// int(1)
// int(2)

// 逆にしても大丈夫
sample01( ato: 2, mae: 3 );
// 出力結果
// int(3)
// int(2)

// 片方だけもいける
sample01( ato: 4 );
// 出力結果
// int(0)
// int(4)

match 式

switch文みたいな処理を、三項演算子のように使える新機能です。

$x = 2;
$sample02 = match ( $x ) {
        1 => '$x は 1',
        2 => '$x は 2',
        default => '$x は それ以外',
};
var_dump($sample02);
// 出力結果
// string(8) "$x は 2"

などなど、簡単に試せるところだけのご紹介で、
今回はあまり大幅な仕様変更はなかったかなと思いますが、
見どころはたくさんあったのではと思います。

ただ、世界に残存する、PHP5 からの アップグレード、PHP7 からのアップグレードは
下位互換のない機能、実装もありますので注意が必要です。

今手元にあるソースと、公式のソースを見比べながらグレードアップに関しては検討してみることをお勧めします。

この記事がお役に立てば【 いいね 】のご協力をお願いいたします!
1
読み込み中...
1 票, 平均: 1.00 / 11
823
X facebook はてなブックマーク pocket
[2024.6.30 CentOS support ended] CentOS server migration solution

[2024.6.30 CentOS support ended] CentOS server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

The person who wrote this article

About the author

Hirofumi Kashiwagi

Like an engineer.

Date of joining: 2010/11/10
Career to date: 2 development companies
Current work: Engineer-like
Qualifications: AWS SAA, GCP PCA

I don't like Kashiwamochi that much.