PHP Conference Ehime 2026

Yaf_Loader::autoload

(Yaf >=1.0.0)

Yaf_Loader::autoloadAutoload a class

Description

public function Yaf_Loader::autoload(string $class_name): bool

Load a class by its name. The class name is converted to a file path: underscores and namespace separators become directory separators.

MVC classes (classes whose names contain _Controller, _Action or _Plugin) are looked up under the application directory, while other classes are looked up in the library directories: the local library for locally registered class prefixes, otherwise the global library.

Parameters

class_name

The class name to load.

Return Values

Returns true on success, or false on failure.

Examples

Example #1 Yaf_Loader::autoload() example

<?php
/*
 * autoload() is normally invoked implicitly by the engine
 * whenever an undefined class is referenced, but it can also
 * be called explicitly to force loading of a class file.
 */
$loader = Yaf_Loader::getInstance("/var/www/shop/application/library");

/* looks up /var/www/shop/application/library/Catalog/PriceService.php */
$loader->autoload("Catalog_PriceService");

/* MVC classes are looked up under the application directory */
$loader->autoload("ProductController");
?>

See Also

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top