PHP接口有属性吗? [英] Do PHP interfaces have properties?

查看:129
本文介绍了PHP接口有属性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP中的接口是否有属性,或者它们只有方法吗?

Do interfaces in PHP have properties, or do they only have methods?

推荐答案

这取决于你的意思属性。如果你的意思是实际的字段,那么不,他们不是。如果您指的是C#中的属性,那么它们可以(因为属性访问器无论如何都是访问器方法的严格语法糖)。事件也是如此(当然,在每种情况下,没有为 get / set 指定实现或添加 / 删除访问者。)

It depends what you mean by "properties". If you mean actual fields, then no, they don't. If you're referring to properties such as those in C#, then yes they can (since the property accessors are strictly syntactic sugar for accessor methods anyway). The same goes for events (though of course, in each case, no implementation is specified for the get/set or add/remove accessors).

更新:由于PHP没有 get / set 访问器的属性,那么答案你的问题是否定的。接口不能携带自己的数据/状态。

Update: Since PHP does not have properties in the sense of get/set accessors, then the answer to your question is no. Interfaces cannot carry their own data/state.

这篇关于PHP接口有属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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