Skip to content

Attempting to alias keywords results in a cryptic Parse error  #9398

@Girgias

Description

@Girgias

Description

This issue is most notable with the array keyword as it is also a built-in type name.

Indeed trying to alias int:

<?php

use int as I;

Parses just fine (however it is impossible to actually use I as a type declaration as you would get the following error Fatal error: Cannot use 'int' as class name as it is reserved in /in/nNOgL on line 5 (see https://3v4l.org/nNOgL) which is its own mess that we might want to catch early)

However, with array (https://3v4l.org/fWrTK):

<?php

use array as a;

We get the following error message:

Parse error: syntax error, unexpected token "array" in /in/F6SlE on line 3

I don't even know if this is actually fixable as this seems like some parser shenanigans.

PHP Version

PHP 8.0.22 - master

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions