Why are the key words abstract and void in a php I

2019-07-24 03:14发布

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

标签: php oop abstract
1条回答
Explosion°爆炸
2楼-- · 2019-07-24 03:57

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.

查看更多
登录 后发表回答