0

There's a magic function to autoload classes (__autoload), I want to know if there a way to load a file without a class.

Something like this:

require ('example_file'); // Trigger __autoloadfiles function

function __autoloadfiles($filename)
{
    $files = array(
        ROOT . DS . 'library' . DS . $filename. '.php',
        ROOT . DS . 'application' . DS . $filename . '.php',
        ROOT . DS . 'application/otherfolder' . DS . $filename. '.php'
    );

    $file_exists = FALSE;

    foreach($files as $file) {
        if( file_exists( $file ) ) {
            require_once $file;
            $file_exists = TRUE;
            break;
        }
    }

    if(!$file_exists)
        die("File not found.");

}

1 Answer 1

1

You can define own function for requiring:

function require_file($file) {
    // your code
}

and then call it

require_file('file');

I guess that there is no way to overload require function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.