Documentation

ClassLoader
in package

ClassLoader implements an PSR-0 class loader.

See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md

$loader = new ClassLoader();

// register classes with namespaces
$loader->addPrefix('Symfony\Component', __DIR__.'/component');
$loader->addPrefix('Symfony',           __DIR__.'/framework');

// activate the autoloader
$loader->register();

// to enable searching the include path (e.g. for PEAR packages)
$loader->setUseIncludePath(true);

In this example, if you try to use a class in the Symfony\Component namespace or one of its children (Symfony\Component\Console for instance), the autoloader will first look for the class under the component/ directory, and it will then fallback to the framework/ directory if not found before giving up.

Tags
author

Fabien Potencier fabien@symfony.com

author

Jordi Boggiano j.boggiano@seld.be

deprecated

since version 3.3, to be removed in 4.0.

Table of Contents

$fallbackDirs  : mixed
$prefixes  : mixed
$useIncludePath  : mixed
addPrefix()  : mixed
Registers a set of classes.
addPrefixes()  : mixed
Adds prefixes.
findFile()  : string|null
Finds the path to the file where the class is defined.
getFallbackDirs()  : array<string|int, mixed>
Returns fallback directories.
getPrefixes()  : array<string|int, mixed>
Returns prefixes.
getUseIncludePath()  : bool
Can be used to check if the autoloader uses the include path to check for classes.
loadClass()  : bool|null
Loads the given class or interface.
register()  : mixed
Registers this instance as an autoloader.
setUseIncludePath()  : mixed
Turns on searching the include for class files.
unregister()  : mixed
Unregisters this instance as an autoloader.

Properties

$useIncludePath

private mixed $useIncludePath = false

Methods

addPrefix()

Registers a set of classes.

public addPrefix(string $prefix, array<string|int, mixed>|string $paths) : mixed
Parameters
$prefix : string

The classes prefix

$paths : array<string|int, mixed>|string

The location(s) of the classes

Return values
mixed

addPrefixes()

Adds prefixes.

public addPrefixes(array<string|int, mixed> $prefixes) : mixed
Parameters
$prefixes : array<string|int, mixed>

Prefixes to add

Return values
mixed

findFile()

Finds the path to the file where the class is defined.

public findFile(string $class) : string|null
Parameters
$class : string

The name of the class

Return values
string|null

The path, if found

getFallbackDirs()

Returns fallback directories.

public getFallbackDirs() : array<string|int, mixed>
Return values
array<string|int, mixed>

getPrefixes()

Returns prefixes.

public getPrefixes() : array<string|int, mixed>
Return values
array<string|int, mixed>

getUseIncludePath()

Can be used to check if the autoloader uses the include path to check for classes.

public getUseIncludePath() : bool
Return values
bool

loadClass()

Loads the given class or interface.

public loadClass(string $class) : bool|null
Parameters
$class : string

The name of the class

Return values
bool|null

True, if loaded

register()

Registers this instance as an autoloader.

public register([bool $prepend = false ]) : mixed
Parameters
$prepend : bool = false

Whether to prepend the autoloader or not

Return values
mixed

setUseIncludePath()

Turns on searching the include for class files.

public setUseIncludePath(bool $useIncludePath) : mixed
Parameters
$useIncludePath : bool
Return values
mixed

unregister()

Unregisters this instance as an autoloader.

public unregister() : mixed
Return values
mixed

Search results