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
10
votes
9 answers
JavaScript Autoloader?
Is there a solution out there where I can have JavaScript/jQuery autoload dependent files when needed? For example, consider this scenario:
I have an autoloader script listening for when a particular script needs to be loaded.
A jQuery dialog()…

Oliver Spryn
- 16,871
- 33
- 101
- 195
10
votes
3 answers
PHP: How to get all classes when using autoloader
I'm using composer to generate autoloader:
"autoload": {
"psr-4": {
"SomeNamespace\\": "src/SomeDir"
}
}
I need to create instances of all classes that implement specific interface. It's fairly easy when not using autoloader, however…

SiliconMind
- 2,185
- 4
- 25
- 49
8
votes
1 answer
PHP spl_autoload_register() doesn't find function
This code:
throws this error:
Fatal error: Uncaught exception 'LogicException' with message…

user697108
- 3,521
- 3
- 20
- 14
8
votes
1 answer
Composer Gives Error, "Class Not Found"
I'm using Windows 10. After making a folder src in the root directory I created two files in it.
Directory Structure (Before running composer install):
│
├── composer.json
├── run.php
│
└── src
├── childclass.php
└── parentclass.php
Two…

Omar Tariq
- 7,536
- 10
- 38
- 57
8
votes
5 answers
Autoload namespaces based on directory structure
According to the top comment on the PHP page spl_autoload_register( ) :
Good news for PHP 5.3 users with namespaced classes:
When you create a subfolder structure matching the namespaces of the >containing classes, you will never even have to…

SAz
- 355
- 4
- 14
8
votes
2 answers
PHP Composer Autoloader Class not Found Exception
The title speaks itself. So here is my project structure:
|src
|Database
|Core
|MySQL.php
|Support
start.php
|vendor
composer.json
index.php
MySQL.php file:

lostbyte
- 466
- 1
- 8
- 21
8
votes
1 answer
Including PHP Defines() using Composer
I'm using Composer for module dependency management (loving using autoload.php instead of a ton of includes and requires!).
I want to include a PHP file that is outside of the root Composer directory (for security) with credentials stored in…

Ryan Brodie
- 6,554
- 8
- 40
- 57
8
votes
2 answers
When exactly is the autoloader called?
I have an autoloader that is registered using spl_autoload_register():
class MyAutoLoader{
public function __construct(){
spl_autoload_register(array($this, 'loader'));
}
public function loader($className){
…

F21
- 32,163
- 26
- 99
- 170
7
votes
3 answers
Is module auto-loading meant to be reliable?
Environment
I have the following folder structure where I keep powershell modules:
C:
PsModules
...
util
util.psm1 (this contains implementation of 'Test-Function')
util.test.ps1
ftp
ftp.psm1
…

alx9r
- 3,675
- 4
- 26
- 55
7
votes
11 answers
Autoloader expected class Symfony2
I'm using symfony 2.3 framework and the autoloader claims to have found the file but no class:
RuntimeException: The autoloader expected class "Sensio\Bundle\
FrameworkExtraBundle\Request\ParamConverter\DateTimeParamConverter"
to be defined in file…

Dr.Knowitall
- 10,080
- 23
- 82
- 133
7
votes
2 answers
How to define custom autoloader in composer?
I am using Nette Framework which uses its own autoloader. How can I define custom autoloader or just exclude the standard one from composer so I can use my own?

Peter Krejci
- 3,182
- 6
- 31
- 49
6
votes
4 answers
Optimize my performance
I'm working on a project with Zend Framework 1.11, Doctrine 2, some Symfony 2 componenents and others tools & libraries.
I'm trying to optimize performance using Xdebug & Webgrind.
I've already found some bottlenecks like parsing Ini config, etc..…

Trent
- 5,785
- 6
- 32
- 43
6
votes
0 answers
phpunit zf2 - class not found
I get this message when trying to test a controller.
Fatal error: Class 'Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase' not found in
However I have configured an autoloader and instanciated a zend class before this point.…

gerard
- 179
- 5
6
votes
2 answers
doctrine2 autloader with cli must use AnnotationRegistry
I must use \Doctrine\Common\Annotations\AnnotationRegistry::registerFile to access the annotation registry in entity files.
This part is required to use driver chain and using orm:schema-tool:creator. but i cant add each class i needed by adding…

Mohammad Hossein Fattahizadeh
- 2,651
- 5
- 35
- 50
5
votes
2 answers
Is it possible to exclude '.' (ie. current dir) from PHP's include path?
From perusing the comments at
http://php.net/manual/en/function.set-include-path.php , it seems to me that '.', or rather basename(__FILE__), is always implicitly added to PHP's include path. Is it at all possible to bypass this path?
In my work…

Emanuel Landeholm
- 1,396
- 1
- 15
- 21