0

I have a php file with many use declarations.

Use.php

<?php
    use 'class/MyClass1';
    use 'class/MyClass2';
?>

File1.php

<?php
    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 ?

Thanks,

1 Answer 1

3

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

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.