为什么关键字在php接口中是抽象的且无效的? [英] Why are the key words abstract and void in a php Interface?

查看:84
本文介绍了为什么关键字在php接口中是抽象的且无效的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遍历php手册站点上的SplSubject接口并注意到。

Going over The SplSubject interface on the php manual site and noticed.

SplSubject {

  /* Methods */
  abstract public void attach ( SplObserver $observer )
  abstract public void detach ( SplObserver $observer )
  abstract public void notify ( void )
}

我无法弄清楚关键字抽象在代码中的作用或原因。还从未见过/未使用过php中的函数返回类型(例如void)?

I can't figure out what the key word "abstract" does in the code or why it is there. Also never seen/used a function return type in php (Such as void)?

谢谢

推荐答案

您在其中看到的接口声明是伪代码

The interface declaration you've seen there is pseudo code. Meaning it is not meant to be executable PHP code.

他们添加类型信息的原因很明显,即显示了该方法的预期返回类型。

They have added the type info for the obvious reason of showing the expected return type of the method.

不要问我为什么他们选择显式添加抽象关键字。通常,接口中声明的每个方法都是抽象的。也许他们想强调一下。

Don't ask me why they have chosen to explicitly add the abstract keyword. Normally every method declared in an interface is "abstract". Probably they wanted to emphasize that.

这篇关于为什么关键字在php接口中是抽象的且无效的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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