[英]Laravel 5.2 `use` syntax
What is the difference in usage within classes of the use
statement, in the examples below: 在以下示例中,
use
语句的类在用法上有什么区别:
Use Sluggable;
Class Invoice extends Model
{
and 和
Class Invoice extends Model
{
Use Sluggable;
Have not been able to find answer to this. 尚未找到答案。
The use statement outside the class is for creating a shorter name than the fully namespaced version of a class you plan to use, eg 该类外部的use语句用于创建比您打算使用的类的全命名空间版本短的名称,例如
use \Package\Super\Awesome\Long\Thingy;
at the top of a file will allow you to instantiate the class anywhere in the file by just 文件顶部的,您可以通过仅实例化文件中任何位置的类
new Thingy();
You can also alias classes this way, eg 您也可以通过这种方式对类进行别名,例如
use \Package\Super\Awesome\Long\Thingy as OtherThingy;
and now you can instantiate this class with 现在您可以使用
new OtherThingy();
The second example you give is to include a trait in the class you are declaring. 您提供的第二个示例是在要声明的类中包含一个特征。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.