Alex Rivera | Logout

PHP namespaces and require

Asked 2011-03-18T09:47:49.720
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?

Edit
Report

1 Answer

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.

answered 2011-03-18T14:53:50.530

Your Answer