php static 调用this,php – 如何在静态方法中使用$this上下文?

$this不在静态方法本身中使用,它在传递给该方法的闭包中使用.

From the Laravel manual:

The Closure is bound to the underlying command instance, so you have full access to all of the helper methods you would typically be able to access on a full command class.

所以这个上下文中的$this是一个Command实例.这是使用PHP的bindTo方法实现的,该方法允许您指定任何给定闭包的范围.

但这种方法并不仅限于Artisan命令.一般来说,我们将此功能称为Facades:

Facades provide a “static” interface to classes that are available in the application’s 07003. Laravel ships with many facades which provide access to almost all of Laravel’s features. Laravel facades serve as “static proxies” to underlying classes in the service container, providing the benefit of a terse, expressive syntax while maintaining more testability and flexibility than traditional static methods.

还有一些其他外观,它们都提供对服务容器内的实例的静态访问.一些更常见的外观和方法是:

> Cache :: get(‘key’)和Cache :: set(‘key’,’value’)> Request :: input(‘some_field’)和Request :: only(‘some_field’)> Log :: info(‘要知道这个……’)> ……

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值