简体   繁体   English

在非类PHP文件中使用“使用”语句可以吗?

[英]Is it ok to use the “use”-statement in non-class PHP files?

the title says it all. 标题说明了一切。 Is it ok to do something like: 可以做类似的事情吗:

<?php

use Some\Very\Long\Namespace\SomeClassName;

SomeClassName::someMethod();

Or does this somehow negatively affect the class loader? 还是这会对类加载器产生负面影响?

All use does is alias a long namespaced name to a different (shorter) local name. 所有use是将长名称空间名称别名为另一个(较短)本地名称。 Your code is exactly equivalent to: 您的代码完全等同于:

Some\Very\Long\Namespace\SomeClassName::someMethod();

So yes, it's perfectly fine. 是的,这很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM