1

I met "PHP Parse error: syntax error, unexpected '{' in ..." error when I tried to execute PHP CLI script.

Error message:

PHP Parse error:  syntax error, unexpected '{' in ??/test.php on line 9

Command:

php -f ./test.php

Code:

<?php
 echo 'begin'.PHP_EOL;

 try {
    echo 'try!'.PHP_EOL;
 } catch (Exception $e) {
    echo 'exception'.PHP_EOL;
 } finally{
    echo 'finally'.PHP_EOL;
 }
 echo 'end';

PHP version: PHP 5.4.16 (cli) (built: Aug 5 2016 07:50:38)

Environment: RedHat 7.3

This is a strange case, this script work well at my Windows PC, but got this issue in Redhat machine.

Have someone once met this case as well?

liuchu
  • 60
  • 10

2 Answers2

2

you need PHP 5.5 or later to use the finally block. Perhaps on the windows machine you have a later version of PHP?

Neil Anderson
  • 1,265
  • 12
  • 19
1

Finally keyword is only supported for PHP version 5.5 or greater

PHP: Exceptions

rai
  • 449
  • 3
  • 10