Questions tagged [spl-autoloader]
55 questions
50
votes
1 answer
How to use spl_autoload() instead of __autoload()
According to http://php.net/manual/en/language.oop5.autoload.php the magic function __autoload() was deprecated as of PHP 7.2.0 and removed as of PHP 8.0.0.
The official alternative is spl_autoload(). See…

Sliq
- 15,937
- 27
- 110
- 143
26
votes
8 answers
Best Way To Autoload Classes In PHP
I'm working on a project whereby I have the following file structure:
index.php
|---lib
|--|lib|type|class_name.php
|--|lib|size|example_class.php
I'd like to auto load the classes, class_name and example_class (named the same as the PHP classes),…

Sjwdavies
- 4,079
- 7
- 38
- 43
12
votes
1 answer
PHP Autoloading with SplClassLoader?
I'm learning about namespaces in PHP 5.3 and I would like to use Namespaces Autoloading. I found this SplClassLoader class, but I can't figure out how it works.
Let's say I have directory structure like this:
system
- framework
- http
-…

Limeni
- 4,954
- 8
- 31
- 33
9
votes
1 answer
PHP: how to autoload interfaces and abstracts
I have this autoloader class to autoload classes initially, but now I want to autoload interfaces and abstracts as well.
So I made the change following this answer,
$reflection = new ReflectionClass($class_name);
# Return boolean if it is an…

Run
- 54,938
- 169
- 450
- 748
8
votes
3 answers
Using spl_autoload() not able to load class
I'm playing around with the SPL autoload functionality and seem to be missing something important as I am currently unable to get it to work. Here is the snippet I am currently using:
// ROOT_DIRECTORY translates to…

John Conde
- 217,595
- 99
- 455
- 496
6
votes
3 answers
PHP spl_autoload
i dont really get the docs for spl_autoload
bool spl_autoload_register ([ callback $autoload_function ] )
from my understanding, it will try to run functions registered when php comes across a class not loaded already. so example,
public…

iceangel89
- 6,113
- 8
- 40
- 55
5
votes
1 answer
php autoloader: why does this work?
I have been experimenting with autoloader class directory mapping techniques, and it has been a bit of a struggle. I managed to come up with a fairly straightforward solution (on the surface), but I'm totally mystified that it works at all, while…

Eric Fuller
- 159
- 1
- 8
5
votes
2 answers
SPL Autoloading best practices
In my include_path on the server-side I have a reference to a pear directory, in '/usr/share/pear/'. Within my applications I include files from a common library, living in '/usr/share/pear/library/' with require_once 'library/file.php'.
I've…

meder omuraliev
- 183,342
- 71
- 393
- 434
4
votes
2 answers
Force autoloading of a specific class
This previous question shows how to force autoloading of all classes.
However I need to force autoloading of just one class on its own. How could I do that?
It mustn't:
Involve changing the class's source code
Rely on any part of the class's source…

Jodes
- 14,118
- 26
- 97
- 156
3
votes
1 answer
PHP Autoloader add Namespace path
My MVC structure is following:
- web
-- Classes
--- Loader.php
-- Core
--- Controller.php
--- Model.php
--- View.php
--- Bootstrap.php
--- DB.php
-- Project
--- Controllers (folder)
--- Models (folder)
---…

Giorgi
- 609
- 2
- 15
- 29
2
votes
1 answer
How can I use Michel Fortin's PHP Markdown Without Autoloading?
I want to use Michel Fortin's PHP Markdown parser. The new style requires the user to set up a PSR-0-compatible autoloader. However, the instructions also state:
If you don’t want to use autoloading you can do a classic require_once to manually…
user636044
2
votes
2 answers
Error when using SplClassLoader
First off, I'm trying my hand using the following SplClassLoader -https://gist.github.com/221634
Here is my file structure:
/root/f1/f2/APS/Common/Group.php
/root/f1/f2/index.php
/root/f1/f2/SplClassLoader.php
Here is my test class called Group…

TechFanDan
- 3,329
- 6
- 46
- 89
2
votes
2 answers
Load php core classes using custom autoloader
I've been searching the database of questions on the forum, but can not get a solution that is oriented to my question.
I come to you, because I doubt has arisen with an autoloader that I'm developing.
The point is this, when I try to instantiate a…

Filiberto Zaá Avila
- 89
- 10
1
vote
1 answer
singleton, factory, autoloader
If one uses autoloader function (with spl_autoload_register), does one need anymore:
singleton: all needed classes will be loaded by autoloader anyway, including database, logs, r&r, fronts etc. so need for "always on" etc. object is not clear to…

Jeffz
- 2,075
- 5
- 36
- 51
1
vote
1 answer
What does everyone mean by: 'spl:_autoload() is default implementation of __autoload()'
I got confused with one thing about php autoloading stuff: the spl_autoload() function. In every answer I found that this function is default implementation of __autoload. Shouldn't PHP define default implementation of __autoload() in itself and…

DoeJane
- 102
- 1
- 6