Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composer - don't use autoload and load single classes?

Brand new to composer. Have it installed and running and have since installed two packages to use on my site by requiring the autoload at the top of the page :

require $_SERVER['DOCUMENT_ROOT'].'/../vendor/autoload.php';

then my use whatever\whatever;

My question is... is there a way I can load single packages rather than everything with the autoload? In this case I am using two packages on the site, but they will never be used together... so... I would think it would make more sense to only load the one(s) I need to use on each page right? There would be a performance difference loading everything with autoload compared to only what I need right?

I've looked around, but can't seem to find an answer to this and if it is possible - maybe I am searching with the wrong terms or looking in the wrong places.

like image 525
user756659 Avatar asked Sep 04 '25 17:09

user756659


1 Answers

You are already only loading the classes you really need. There is no performance benefit not doing this without the autoloader, but a huge drawback: You will be forced to add every needed class manually if you don't use the autoloader.

You will have a case here if you can prove by measurement that one approach is significantly better than the other.

like image 168
Sven Avatar answered Sep 07 '25 06:09

Sven