PHP名称空间和要求 [英] PHP namespaces and require

查看:45
本文介绍了PHP名称空间和要求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在一个主要的index.php文件中包括几个文件. 我正在使用名称空间.

我可以使用include/require并让文件使用与index.php相同的名称空间,而无需在每个包含的文件中指定名称空间并使用语句吗?

解决方案

PHP名称空间在文件级别作用域.

如果a.php在名称空间内,并且包含b.php,但是b没有指定名称空间,则将采用a中定义的名称空间. /p>

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?

解决方案

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.

这篇关于PHP名称空间和要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆