php8.5
Home/ Manual/ yaf / yaf_loader/ Yaf_Loader::getInstance

Yaf_Loader::getInstance

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Retrieve the Yaf_Loader instance

Description

Yaf_Loader::getInstance(string $local_library_path = null, string $global_library_path = null): Yaf_Loader|false

Retrieve the singleton Yaf_Loader instance.

If the library paths are given, they are applied to the existing instance.

Parameters

local_library_path

The local library directory, usually the same as the application.library.directory ini setting.

global_library_path

The global library directory. If not given, the local one is used.

Return Values

The Yaf_Loader instance, or false if the loader has not been initialized (which is normally done by Yaf_Application).

Examples

Yaf_Loader::getInstance example

php
<?php
$app = new Yaf_Application(__DIR__ . "/conf/application.ini");

/* Yaf_Application has initialized the loader, so the
 * singleton instance is available now */
$loader = Yaf_Loader::getInstance();
$loader->registerNamespace("Vendor", APPLICATION_PATH . "/library/Vendor");
?>

Yaf_Loader::getInstance before initialization

php
<?php
/* no Yaf_Application has been created yet */
var_dump(Yaf_Loader::getInstance());
?>

The above example will output something similar to:

output
bool(false)

See Also

  • Yaf_Loader::setLibraryPath
  • Yaf_Loader::getLibraryPath

Source: reference/yaf/yaf_loader/getinstance.xml · from the official PHP manual (php/doc-en)