I've seen a very similar question (and answer) here: https://stackoverflow.com/a/20933938/339440 ...but it doesn't quite do what I need.
I have this:
<?php
namespace My\Project {
function foo() {
...do stuff...
return $something;
}
}
namespace { // global namespace
function prefix_foo() { return My\Project\foo(); }
}
What I want in the global namespace is this:
namespace {
use function My\Project\foo as prefix_foo;
}
...but any time I try to call prefix_foo() in the global namespace I get a "function not defined" error. I'm using PHP 5.6.25. Can anyone tell me why this doesn't work? It appears that this works just fine without the "as" (per the linked question above).
EDIT: Okay, I figured out that it's happening because the definitions and the actual usage are happening in two different files. It appears you have to put the "use" clause in each individual file that might use the functions.
This would be really unwieldy in this case, as I have to "define" a whole bunch of functions this way and repeating a giant block of use clauses in each one would defeat the purpose.
Is there a way to have the "use" statement work from one PHP file to the next (via include)?