|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80552 Match is a reserved word
Submitted: 2020-12-25 15:57 UTC Modified: 2020-12-25 21:16 UTC
From: rasmus at mindplay dot dk Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 8.0.0 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: rasmus at mindplay dot dk
New email:
PHP Version: OS:


 [2020-12-25 15:57 UTC] rasmus at mindplay dot dk
PHP 8.0 breaks any existing code with a class named "match", which became a reserved word for some reason.

PHP 7.0 intentionally loosened such reserved word restrictions, per the original release announcement here:

It would be nice if PHP continued in that vein to avoid more variations of this problem.

Parser failure is demonstrated with a minimal repro here:

A quick google search reveals at least two major projects (PHPUnit and MediaWiki) affected by this change - here's a handful of examples from a quick google search:


Test script:

class Match {}

class Matcher
    public function match(): Match {}

$matcher = new Matcher();

$match = $matcher->match();

Expected result:
It would be nice if this could be treated as a bug, and could be fixed with a minor release, such that packages that were broken by this change can be versioned correctly against e.g. PHP ^8.0.1, before everyone goes and starts renaming classes and functions.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-12-25 16:01 UTC]
This was explicitly accepted as part of an RFC and is therefore unlikely to be reversed:
 [2020-12-25 16:10 UTC]
> Globally reserved words as property, constant, and method names within classes, interfaces, and traits are now allowed. This reduces the surface of BC breaks when new keywords are introduced and avoids naming restrictions on APIs.

All of these already apply for match:

All other keywords also still are not allowed in class names or namespaces:
 [2020-12-25 21:16 UTC]
-Status: Open +Status: Not a bug -Operating System: Linux +Operating System:
 [2020-12-25 21:16 UTC]
As already indicated by prior comments, this is not a bug as it's expected and was explicitly accepted with the RFC vote.
 [2020-12-26 10:10 UTC] rasmus at mindplay dot dk
Please consider this a feature request then.

There's no practical reason a parser needs to care which name comes after the class or function keyword, as long as it's a name - so this kind of error is just weird and distracting, and forces people into making breaking changes in libraries for no practical reason.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Jul 06 16:05:46 2022 UTC