An autoloader is a feature to allow classes and functions from different files to be included automatically when they are first called. This saves the need to explicitly include all of the files, or create a monstrous global functions/classes file.
Questions tagged [autoloader]
388 questions
66
votes
13 answers
Autoloader for functions
Last week I learned that classes can be included in your project by writing an __autoload() function. Then I learned that using an autoloader isn't only a technique but also a pattern.
Now I'm using the autoloader in my project and I've found it…

Shoe
- 74,840
- 36
- 166
- 272
30
votes
3 answers
Why include __DIR__ in the require_once?
For example, I always see autoloaders called like this:
require_once __DIR__ . '/../vendor/autoload.php';
What is the difference between that and the more concise
require_once '../vendor/autoload.php';
?

Dan Goodspeed
- 3,484
- 4
- 26
- 35
20
votes
3 answers
CodeIgniter: "Unable to load the requested class"
On my WAMP box, I did the following:
Added a file called /application/libraries/Foo.php
Foo.php is a class, and it's name is Foo
In /application/config/autoload.php, I added $autoload['libraries'] = array('foo');
Everything works fine. When I…

StackOverflowNewbie
- 39,403
- 111
- 277
- 441
19
votes
6 answers
Class Firebase\JWT\JWT not found
I want to use pure firebase/php-jwt library in my code. Firstly, I go to /var/www/html/ and like the official library page is suggesting, I do this
composer require firebase/php-jwt
After I run this command, I see that a new vendor folder is…

Jacobian
- 10,122
- 29
- 128
- 221
17
votes
1 answer
How to create a PSR-4 autoloader for my project?
I am creating a PHP project and want to implement PSR-4 autoloading.
I don't know which files I need to create in the vendor directory to implement autoloading for class files.

Kshitij Verma
- 617
- 1
- 4
- 12
17
votes
1 answer
using multiple autoloaders php
Hello I am trying to use SILEX micro framework together with my own library full of classes and therefore I am stuck with 2 loaders that results in a error that the loader can't load classes.. Is there a way to use these 2 loaders simultaneously…

Reshad
- 2,570
- 8
- 45
- 86
16
votes
1 answer
how does php autoloader works
Does php class Autoloader opens a file and checks for the class name? I have been looking on how is it actually implemented. One thing I know that its recursive? If I'm wrong please let me know
As mentioned overhere : autoloader brief over view
How…

meWantToLearn
- 1,691
- 2
- 25
- 45
13
votes
2 answers
PHP-Like Autoloader using Node.js
I'm slowly transitioning from PHP to Node.js and was trying to find something similar to composer dumpautoload. Thanks to PSR-4, it's easy to get access to any class in any file in PHP when using this command with simple use statements at the…

Nicolas Bouvrette
- 4,295
- 1
- 39
- 53
13
votes
3 answers
Can php spl_autoload_register & composer autoloader work together?
After a little bit of research and have been unable to locate a solution to my problem. I am utilizing an API that is namespaces that I downloaded via composer. The API has it dependences that I allow composer to manage and autoload for me. Separate…

DevOverlord
- 456
- 3
- 19
13
votes
5 answers
How to call __autoload() in php code
I am new to php and I want to use php5's __autoload functionality in my code. I wrote below code in my index.php but I don't understand how and when I should call __autoload function.
function __autoload($class) {
if (file_exists($class .…

pabz
- 534
- 1
- 5
- 15
12
votes
1 answer
Why am I getting PHP Fatal error: Uncaught Error: Class 'MyClass' not found?
This works:
class MyClass {
public $prop = 'hi';
}
class Container {
static protected $registry = [];
public static function get($key){
if(!array_key_exists($key, static::$registry)){
static::$registry[$key] = new…

Jeff Puckett
- 37,464
- 17
- 118
- 167
12
votes
4 answers
Laravel Alias not finding class
I am trying to register an Alias to a class, but Laravel can't find the class, i can reference the class directly in my controller, so i know its loaded correctly.
here is my code:
'aliases' => array(
'FrontendAssets' =>…

user2834482
- 437
- 2
- 6
- 14
12
votes
4 answers
How to fix error of composer post-install-cmd script?
I would like to use composer script to do some post installation such as copying files from bootstrap vendor folder to my web application public folder. I have a baby experience with PHP world and web application development.
I'm trying to learn…

Artisan
- 4,042
- 13
- 37
- 61
11
votes
2 answers
Python modules autoloader?
How can I autoload all my modules that kept in different directories and sub directories?
I have seen this answer which is using __import__, but it is still not the autoload that I have in mind.
I'm thinking something similar to PHP autoloader. Even…

Run
- 54,938
- 169
- 450
- 748
11
votes
2 answers
I do not understand why someone need composer?
I think there is no need to include composer for loading any library etc. Loading some libraries is not hard task. Its easy to include...
Download library > extract > put into your project > use it
This task is only one time per project. I mean its…

thomas
- 331
- 2
- 8