syntax error, unexpected ‘match’

Description

This error is related to match being a PHP keyword. Since PHP 8.0, it cannot be used anymore as a class or interface name. When moving from PHP 7 to 8, any traditional usage of match where a class name is expected shall produce such an error.

In the illustrations, no more details are provided about the reason why match is not allowed. Other situation may provide better hints.

This error applies to all PHP keywords. match is only the most common, as it is a new PHP 8.0 keyword.

Example

<?php

// Cannot use Match here.
interface X extends Match { }

// Cannot use Match here.
class Y implements Match {

    // Cannot use Match here.
    use Match;
}

?>

Solutions

  • Rename Match to something that is not a PHP keyword.

  • Stay on PHP 7.x.