IMHO creating a class file on the fly and putting it in the site's files folder is not really a good idea, especially for production sites.

The files folder is not normally in version control, and I am often running into the problem of it missing when I switch developer environments. In general, the files folder just isn't reliable.

Especially since currently, for some reason, Drupal will try to include the generated sites/default/files/mailsystem/ file on every page, causing a fatal error if it is missing, but that is for another issue.

I get that it might be the best way to generate and save the file, but there should at least be another way to include the file, such as maybe the sites/all/libraries folder, or a custom module folder?

There may already be a way to do this, but its just not documented?

If I can figure this out I'll make a patch.



I have a site with the files dir outside of the drpalroot. This lead to a require() error when an attempt is made to load the class. Also, the files are not in version control. It would be nice if there was an option to download the file from the UI, as the ability to generate it there is great.

To fix:
1. copied the file from .../files/mailsystem/
2. place in a custom module's includes dir and .info file using
files[] = includes/
remove original file from {registry} table
DELETE FROM registry WHERE name='[appropriate-name]' AND module='mailsystem';
drush cc all

new605 bytes


I agree. I've hit this problem recently and it is a pretty violent crash when the generated file is not present or accessible. I wonder if it makes sense to generate a custom module from this module as you suggested. At the very least maybe generate a custom module and make it downloadable with documentation on how to add it to your site.

Everett, I've followed your fix and it works great. Attached is the module I created based on your guidelines. Hopefully this can serve as a reference for anyone else that hits this.



FWIW, the 7.x-3.x branch should eliminate the need for writing PHP files entirely.

As someone who just hard-crashed a production server environment: Yes, Please Fix this process!

This also breaks when s3 is the default filesystem. Classes generated there won't be autoloaded at all. Looking forward for a fix in the 3.x branch.

Status:Active» Closed (duplicate)

As @Les Lim mentions, this problem is completely eliminated in the 3.x branch. See #1508104: [PATCH] Replace dynamically generated class with delegation. The new 3.0-alpha1 is only two commits different from the stable 2.x release and appears to function identically. I'm throwing my hat in that ring. Given the lack of movement here, I'm marking this as a duplicate.

@TravisCarden Ok, glad to know it's fixed in 3.0-alpha1, but please link to the issue that this one is a duplicate of.

Issue summary:View changes
new1.69 KB

Above solution as a patch to the 7.x-2.x branch