Skip to content
Latchkey

PHP "Parse error: syntax error, unexpected ..." in CI

PHP parses a file before executing it. A syntax error stops the parse with "unexpected <token>". In CI this is frequently a real typo, or code using a newer language feature (enums, named arguments, readonly) on an older PHP than the one that wrote it.

What this error means

A PHP step fails immediately with "PHP Parse error: syntax error, unexpected ... in <file> on line N". The error points at the exact file and line that fails to parse.

composer
PHP Parse error:  syntax error, unexpected token "enum", expecting
"function" or "const" in /app/src/Status.php on line 5

Common causes

A genuine syntax mistake

A missing semicolon, brace, or arrow that breaks the parse on the indicated line.

A newer language feature on an older PHP

Code uses syntax (enum, readonly, named args, match) introduced in a PHP version newer than the one CI runs, so the parser rejects it.

How to fix it

Lint the file and fix the syntax

Use php -l to confirm the parse error and locate it.

Terminal
php -l src/Status.php
# fix the reported line, then re-run

Match the CI PHP version to the syntax you use

If the feature is intentional, run CI on a PHP version that supports it.

.github/workflows/ci.yml
- uses: shivammathur/setup-php@v2
  with:
    php-version: '8.2'   # supports enums, readonly, etc.

How to prevent it

  • Run php -l (or a lint step) in CI to catch parse errors early.
  • Match the CI PHP version to the language features your code uses.
  • Use a matrix to validate syntax across every PHP version you support.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →