John smith John smith - 2 years ago 123
PHP Question

Php require use keyword

I have a php file with many use declarations.


use 'class/MyClass1';
use 'class/MyClass2';


include_once 'Use.php'

I would like to include it on another php file but it doesn't seem to work.

Must I need to copy/paste all Use declaration on every php file ?


Answer Source


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

So you can't move use statements into a separate file, unfortunately.

If you've got multiple files that have a large set of similar dependencies, it could be a sign that your code needs reorganising, but that's a separate discussion.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download