PHP Conference Ehime 2026

Yaf_Loader::import

(Yaf >=1.0.0)

Yaf_Loader::importLoad a PHP script

Beschreibung

public static function 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.

Parameter-Liste

file

The file to load.

Rückgabewerte

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

Beispiele

Beispiel #1 Yaf_Loader::import() example

<?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");
    }
}
?>

Beispiel #2 A file is imported only once

<?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")
);
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

bool(true)

Siehe auch

add a note

User Contributed Notes

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