Can require_once work beyond it's own function?

How to make require_once work and apply from within a function?

$myfile = "myfile";

function getFunctions($file) {
	require_once("$file.php");   // twist.php has definition of jpegToHex()
}

getFunctions($myfile);

var_dump(jpegToHex("local.jpg"));    // error

I have a loader, which loads functions from another file. But I have no idea how to make require_once() work outside of it’s scope. I need functions from included file.

Don’t ask why I make entire new function to do exactly same. It’s part of a bigger script.

it depends. the function has it’s own scope, so variables are restricted to that scope, but function definitions should be ok (otherwise autoloaders wouldn’t work).

could you post the exact error you get?

As I threw around couple functions it seemed to have worked.

So it’s solved now, thanks.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.