Example:
namespace Somenamespace;
use Somenamespace\Someclass;
use Somenamespace\otherclass;
class Template{
public function display($templ){
load_template($templ);
}
}
function load_template($file){
unset($file);
require func_get_arg(0);
}
$template = new Template();
$template->display('file.php');
Now I want to access "Someclass" in file.php, without having to declare it first in the "use" statement. eg. someclass::dostuff(); (without the namespace)
Is it possible?
Simply: no. See note bellow the example http://www.php.net/manual/en/language.namespaces.importing.php#example-247
Importing rules are per file basis, meaning included files will NOT inherit the parent file's importing rules.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With