11

I need to include several files in a main index.php file. I'm working with namespaces.

Can I use include/require and make the files use the same namespace as index.php without specifying the namespaces and use statements in each included file?

1 Answer 1

27

PHP namespaces are scoped at the file level.

If a.php is inside a namespace, and it includes b.php, but b doesn't specify a namespace, it will not adopt the namespace defined in a.

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

2 Comments

Is there any way to explicitly have the imported symbols adopt the importing file’s namespace?
Not as far as I know, no.

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.