LoginSignup
1
0

More than 3 years have passed since last update.

[PHP]try-catch-finallyのfinally句で、syntax errorが出る原因

Last updated at Posted at 2021-01-13

PHPのtry-catch-finally文の、finally句でsyntax errorが出た。
エラー内容は以下のような感じ。

PHP Parse error:  syntax error, unexpected '{' (以下省略)

パッと見間違ってないし、finally句を除くと処理がうまくいく。

調査を続けたところ、finally句は、PHP5.5より前のバージョンだと、使えないらしい。

対象サーバのPHPのバージョンを確認してみる

$ php -v
PHP 5.3.3 (cli) (built: Jul  9 2015 17:39:00)
(以下省略)

PHPのバージョンが5.3.3・・?
5.5より古いやないかい!

PHPのバージョンが7以上のサーバで実行したところ、うまくいきましたとさ!

結論

PHPのtry-catch-finallyのfinally句で、syntax errorが出た場合は、バージョンが5.5より前のバージョンでないか確認 & 該当の場合はfinally句は使わないようにすべし!

参考

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