Why are the key words abstract and void in a php Interface?

瘦欲@ 提交于 2019-12-11 02:35:20

问题


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 )
}

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

Thank you


回答1:


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.



来源:https://stackoverflow.com/questions/28569326/why-are-the-key-words-abstract-and-void-in-a-php-interface

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!