Question

I have a class under vendor/Test-Namespace/Client/client.php

Can I use composer with Symfony2 and the PSR-4 standard? So that I can do the usual:

use TestNamespace/Client/Client;

...
{
    $client = new Client();
}
Was it helpful?

Solution

The PSR-4 standard has only been implemented in the first days of January 2014, and when releasing the maintainers have asked to let some time pass before it is actually put into action, i.e. start using it in February 2014.

My own idea about request is that any current Composer release starts complaining about an update after 30 days, so letting a month pass gives the slight chance that anyone using your library is able to create a PSR-4 autoloader. Older versions will fail to do so.

Apart from that, the declaration of an autoloader is simply stating a namespace and a path to look for, and PSR-4 does not really differ from PSR-0.

There is absolutely no change in the way you use the classes.

If you fully control the environment where your PSR-4 autoloading is being used, then you can feel free to use it right away. If you are publishing an important library for public consumption, you better wait a day or two until it is safe to assume everybody using your library has updated to a Composer that allows using PSR-4.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top