php 类中use,PHP:在类定义中使用'use'

最近我遇到了一个use在类定义中使用语句的类.

有人可以解释它到底做了什么 - 因为我找不到任何有关它的信息.

我理解它可能是一种将它从给定文件的全局范围移开的方式,但它是否也允许给定的类继承多个父类 - 因为extends只允许一个父类引用?

我看到的例子是Laravel原始安装的User模型:

use Illuminate\Auth\UserTrait;

use Illuminate\Auth\UserInterface;

use Illuminate\Auth\Reminders\RemindableTrait;

use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {

use UserTrait, RemindableTrait;

/**

* The database table used by the model.

*

* @var string

*/

protected $table = 'users';

/**

* The attributes excluded from the model's JSON form.

*

* @var array

*/

protected $hidden = array('password', 'remember_token');

}

我已经看到这个模型的一些例子实际上使用了UserTrait类中包含的方法- 因此我怀疑,但我真的想了解更多关于所附use语句的含义.

use关键字必须在文件的最外层范围(全局范围)或命名空间内声明中声明.这是因为导入是在编译时完成的,而不是运行时,所以它不能是块作用域.以下示例将显示use关键字的非法使用:

然后是例子:

namespace Languages;

class Greenlandic

{

use Languages\Danish;

...

}

这表明它是use关键字的错误使用- 任何线索?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值