php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79989 new `match` keyword is inconsistant in syntax errors
Submitted: 2020-08-18 10:02 UTC Modified: 2020-08-18 10:59 UTC
From: call dot user dot func at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Scripting Engine problem
PHP Version: 8.0.0beta1 OS: W10
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: call dot user dot func at gmail dot com
New email:
PHP Version: OS:

 

 [2020-08-18 10:02 UTC] call dot user dot func at gmail dot com
Description:
------------
Stated in this RFC: https://wiki.php.net/rfc/match_expression_v2#backward_incompatible_changes

we have  this new keyword `match` which now result in syntax errors when used as a namespaces, class names, function names, global constants.

Well, this behaviour is not consistant with the RFC and also inconsistent between the alpha3 and all other pre-release versions of php8.

My tests are in the attached test scripts.

Greetz Roland

Test script:
---------------
<?php

define("match", 1);  // no error in php8.0.0beta1
class Match{} // error in php8.0.0beta1
function match(){} // error in php8.0.0beta1
namespace match{} // only error in php8.0.0alpha3
namespace Foo\Bar\Match; // only error in php8.0.0alpha3


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-08-18 10:32 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Package: *General Issues +Package: Scripting Engine problem -Assigned To: +Assigned To: cmb
 [2020-08-18 10:32 UTC] cmb@php.net
The behavioral change of the namespace declaration is due to
RFC: Treat namespaced names as single token[1], which only has been
implemented for 8.0.0beta1, and is mentioned in UPGRADING[2].

[1] <https://wiki.php.net/rfc/namespaced_names_as_token>
[2] <https://github.com/php/php-src/blob/php-8.0.0beta1/UPGRADING#L207-L210>>
 [2020-08-18 10:43 UTC] call dot user dot func at gmail dot com
Ok i understand this new RFC. When you say it is implemented in beta1, why it does not throw a error in this version when using namespace match{}?

Also what's with all the other cases i've mentioned?

Really not a bug?
 [2020-08-18 10:55 UTC] cmb@php.net
A string (like used in define()) is never an issue wrt. reserved
keywords.  `class Match` and `function match` are errors now,
since `match` is a reserved keyword.

The namespace declarations are special cased in PHP 8, so using a
stand alone `match` or having `Match` as part of a namespace
declaration name is allowed now.

So everything behaves as expected; thus not a bug. :)
 [2020-08-18 10:59 UTC] call dot user dot func at gmail dot com
Perfect. Thanks for answering. Sure, define() is just a string, when defining. When try to output/use  it, is is now correctly a syntax error.

Didn't knew of the namespace special behaviour and i also mixed up the match RFC change with the namespace RFC.

Thanks. Not a bug :)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 21:01:35 2025 UTC