I tested back and forth some time now with PHP 5.5.3, and while I have to report that during testing things looked broken (more likely due to me producing a VM with that version on short notice, with no settings and the wronk keyboard layout), in the end I cannot reproduce the error. I'd say that autoloading for traits works as advertised.
Now here is what I did:
In the home directory:
composer.json
{
"autoload": {"psr-0":{"User":"src"}}
}
Also:
test.php
<?php
require "vendor/autoload.php";
class Auth {
use User;
}
new Auth;
In the directory src
:
src/User.php
<?php
trait User {}
Running composer install
creates vendor/composer/autoload_namespaces.php
with this array entry:
'User' => array($baseDir . '/src'),
And executing the testscript works for me.
Note that it is important to have the naming of the files correct. They have to match exactly according to PSR-0 rules (or PSR-4 if you prefer using namespaces), including case sensitive correct filenames.
If you have a trait named "User", and you define PSR-0 autoloading like "User": "Validation", the expected situation would be that the following file exists: Validation/User.php
with the content:
<?php
trait User {
// stuff here
}
This trait will then be able to be autoloaded after running at least once composer install
.