为什么php接口中的关键字abstract和void? [英] Why are the key words abstract and void in a php Interface?

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

问题描述

浏览 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)?

谢谢

推荐答案

您在那里看到的接口声明是伪代码.这意味着它不是可执行的 PHP 代码.

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.

不要问我为什么他们选择显式添加 abstract 关键字.通常在接口中声明的每个方法都是抽象的".可能他们想强调这一点.

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接口中的关键字abstract和void?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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