Skip to content

Enum is treated as invalid class name #178

@dercoder

Description

@dercoder

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions