php 类中use,oop-PHP:类定义内的“ use”

最近,我遇到了一个在类定义内使用use语句的类。

有人可以解释它的确切作用-因为我找不到有关它的任何信息。

我知道这可能是将其从给定文件的全局范围中移出的一种方法,但是它也许还允许给定类也从多个父类继承-因为use仅允许一个父类引用?

我看到的示例在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');

}

并且我已经看到了一些使用use类中包含的方法的该模型的示例,因此引起了我的怀疑,但我确实想进一步了解封闭的use语句的含义。

PHP文档说:

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

接下来是示例:

namespace Languages;

class Greenlandic

{

use Languages\Danish;

...

}

这将表明它是use关键字的不正确使用-有任何线索吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值