Skip to content

Enum is treated as invalid class name #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dercoder opened this issue Apr 29, 2025 · 0 comments
Open

Enum is treated as invalid class name #178

dercoder opened this issue Apr 29, 2025 · 0 comments

Comments

@dercoder
Copy link

Version: v4.1.8

Bug Description

Creating a class with the name "Enum" does not work because its in the keyword list.

Steps To Reproduce

$file = new PhpFile();
$namespace = $file->addNamespace('Test');
$class = $namespace->addClass('Enum');

This will throw an exception:

In ClassLike.php line 89:
                                         
  Value 'Enum' is not valid class name.  

The reason:
Image

Expected Behavior

Enum is a valid class name when its under a namespace:

<?php

namespace Test;

class Enum
{
}

Possible Solution

I suggest to remove the keyword from the list or to create a real list of unsupported PHP class names:
https://www.php.net/manual/en/reserved.keywords.php +

  • self
  • static
  • parent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant