PHP:包含文件中的“使用”? [重复]

This question already has an answer here:

When using namespaces in PHP you can do things like:

<?php
use \mynamspace\MyClass;
$a = new MyClass();
?>

Is it possible to put the use... line in an include file? If there are dozens oft those use statements it is very annoying to write them in every single file you need them.

But the use statement is only working for the current file and is ignored in the files that include it.

Any ideas?

</div>

Unfortunately not. PHP's namespace constructs are in a per file basis. The PHP manual sums it up as such:

Importing rules are per file basis, meaning included files will NOT inherit the parent file's importing rules.

http://php.net/manual/en/language.namespaces.importing.php