I have a static class I want to call in my module.

Does the file containing the class definition need to have a special name convention, such as MyStaticClass.class.php? The file is in my module folder.


2 Answers 2


The only part of the Drupal coding standards that talks of filenames doesn't say how to name PHP files containing class definitions.

Files containing PHP code, which are not the main module file, or the installation file, usually use the extension .inc, in Drupal 7 and previous versions. As there isn't any possibility of conflict between files used from different modules, you can decide the rest of the filename.

Note that Drupal 7 uses a registry, which contains a list of files defining classes. If you have a file defying a class, you just add a line similar to the following one, on the .info file.

    files[] = 

In this way, the file will be automatically loaded by Drupal when you reference the class, such as when you instance an object of that class, or you call a method defined in that class.

Drupal 8 uses .php as extension for PHP files containing a class, such as Node.php, Uuid.php, and Database.php.

  • 1
    +1 for mentioning files[] and that ONLY class files go in there.
    – Rudie
    Sep 15, 2012 at 18:18

I'd go with [literal class name].inc. That's how most modules do it.

The class names themselves are Drupal coding standardized: CamelCased. Views, however doesn't follow those standards, so if you're making a Views plugin, I wouldn't call it MyViewsPlugin, but my_views_plugin, to keep in line with Views itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.