LoginSignup
1
0

More than 3 years have passed since last update.

php7.4からついにクラスのメンバ変数に型宣言できるようになった

Last updated at Posted at 2019-12-19

php7.4からクラスのプロパティは、新たに型宣言をサポートするようになりました。

遂に!って感じですね。
php7系、特に7.3など使用しているとアップデートするか悩ましいですね。
パフォーマンスの改善も結構されているみたいですし。

<?php
class User {
    public int $id;
    public string $name;
}
?>

上の例では、
$user->idにはintの値だけを、$user->nameにはstringの値だけを代入できるように強制します。

PHP 7.3.x から PHP 7.4.x への移行

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0