Traits with Symfony 1.4
PHP 5.4 is so nifty. And traits are mad cool.
And you might be in the same situation as me: Big product with a huge amount of customer benefit built on Symfony 1.4 with years yet to maintain it and expand on it.
So you might want to start using traits, just like me. The first thing to do was, of course, to just do it:
**Fatal error:** Trait ‘ImageUpload’ not found in **/path/to/project/lib/MyClass.php**
Symfony was not autoloading traits.
Which is good. Symfony autoloads selectively, and you might not want to autoload every stray php file a stray programmer might have forgotten inside lib. (kidding)
I found by poking around in the Symfony 1.4 sources that the method actually selecting which files get autoloaded and cached is *sfAutoloadConfigHandler::parseFile*. It contains a regex that filters files to contain a line that starts with nothing or whitespace, followed by the words *final* or *abstract*, and then *class* or *interface*.
So a quick and dirty way to get traits autoloaded is to include a commented out mock class or interface definition in the trait file.