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

Yaf_Loader::import

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Load a PHP script

Description

Yaf_Loader::import(string $file): bool

Load a PHP script file once. If the file is not an absolute path, it is looked up under the local library directory.

A file is only included once; calling Yaf_Loader::import again with the same file returns true without re-including it.

Parameters

file

The file to load.

Return Values

Returns true on success (including when the file was already loaded), or false on failure.

Examples

Yaf_Loader::import example

php
<?php
class Bootstrap extends Yaf_Bootstrap_Abstract
{
    public function _initHelpers()
    {
        /* a relative path is looked up under the library
         * directory, i.e. APPLICATION_PATH/library/functions/format.php */
        Yaf_Loader::import("functions/format.php");
    }
}
?>

A file is imported only once

php
<?php
/* an absolute path is used as-is */
Yaf_Loader::import("/var/www/shop/application/library/Legacy/csv_export.php");

/* importing the same file again does nothing and returns true */
var_dump(
    Yaf_Loader::import("/var/www/shop/application/library/Legacy/csv_export.php")
);
?>

The above example will output something similar to:

output
bool(true)

See Also

  • Yaf_Loader::autoload

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