【发布时间】:2014-01-02 18:53:48
【问题描述】:
接口中的关键字abstract是什么意思。 我正在尝试在界面中编写抽象关键字。
<?php
interface I
{
abstract function test ();
}
class A implements I{
public function test ($offset)
{
}
}
$x=new A();
?>
出现错误:
Fatal error: Access type for interface method I::test() must be omitted in test.php on line 4
但是这里所有的方法都是抽象的http://www.php.net/manual/en/class.arrayaccess.php,我已经实现了这个工作正常。
错误的原因是什么,因为它对预定义接口 ArrayAccess 工作正常
【问题讨论】:
-
不需要密钥
abstract,因为接口中定义的所有方法都必须在类中实现。 -
我的问题是,如果你打开这个链接php.net/manual/en/class.arrayaccess.php 这是一个接口 ArrayAccess,其中所有方法都是抽象的,但我正在尝试编写自己的接口方法抽象我得到错误
-
接口中的所有方法都已经是抽象方法了。您不需要隐含地告诉每个方法它是抽象的,因为它已经是默认的(我只是不知道为什么会出现错误,他们可以简单地忽略它)。
标签: php