php-generator icon indicating copy to clipboard operation
php-generator copied to clipboard

Enum is treated as invalid class name

Open dercoder opened this issue 8 months ago • 0 comments

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

dercoder avatar Apr 29 '25 14:04 dercoder