PHP中最新的静态绑定到底是什么? [英] What exactly are late static bindings in PHP?

查看:86
本文介绍了PHP中最新的静态绑定到底是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP中最新的静态绑定到底是什么?

What exactly are late static bindings in PHP?

推荐答案

您肯定需要阅读

You definitely need to read Late Static Bindings in the PHP manual. However, I'll try to give you a quick summary.

基本上,可以归结为self关键字不遵循相同的继承规则的事实. self始终解析为使用它的类.这意味着,如果您在父类中创建一个方法并从子类中调用它,则self不会像您期望的那样引用该子代.

Basically, it boils down to the fact that the self keyword does not follow the same rules of inheritance. self always resolves to the class in which it is used. This means that if you make a method in a parent class and call it from a child class, self will not reference the child as you might expect.

最新的静态绑定为static关键字引入了新用法,从而解决了这一特殊缺点.当您使用static时,它表示您首次使用它的类,即.它绑定"到运行时类.

Late static binding introduces a new use for the static keyword, which addresses this particular shortcoming. When you use static, it represents the class where you first use it, ie. it 'binds' to the runtime class.

这是背后的两个基本概念.在播放static时,selfparentstatic的操作方式可能很微妙,因此,我不建议赘述,而是强烈建议您研究手册页示例.一旦您了解了每个关键字的基础知识,这些示例就非常有必要,以了解您将获得什么样的结果.

Those are the two basic concepts behind it. The way self, parent and static operate when static is in play can be subtle, so rather than go in to more detail, I'd strongly recommend that you study the manual page examples. Once you understand the basics of each keyword, the examples are quite necessary to see what kind of results you're going to get.

这篇关于PHP中最新的静态绑定到底是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆