Fatal error during add a field to a content type with a custom Field Type I'm working on Drupal 8 and I create a custom field type so

When I tried to add a field to a content type Drupal give me this error


  Fatal error: Cannot redeclare class Drupal\any_to_show\Plugin\Field\FieldType\AnyToShowItem in /var/www/public/sites/all/modules/something/src/Plugin/Field/FieldType/AnyToShowItem.php on line 105


I'm confused because it suppose that the file is the definition and it says that I'm redeclaring the class, I search whole site but nothing.

I was grateful if somebody can help me.
thanks in advance
This happened to me, and the solution was making sure that the file name matches the class name defined within, so in your case, the class name MUST be AnyToShowItem.

This is because the PSR-4 auto-loader would be trying to load .../sites/all/modules/something/src/Plugin/Field/FieldType/AnyToShowItem.php if the class AnyToShowItem doesn't exist. But if the class defined within doesn't match the filename, then AnyToShowItem will still be undefined but the class that IS contained in the file will be. So the next time the AnyToShowItem class is attempted to be constructed, the file is loaded again in a futile attempt to define the class, but the class within will already have been defined, and thus the redefinition error will be thrown