抽象类不能声明为public?

时间:2014-08-26 16:01:16

标签: php oop

我正在drupal自定义模块中编写代码

在abstract

之前添加public关键字时会抛出错误
public abstract class testParent {
  public function abc() {
    return 1;
  }
}

// Class to extent abstract class property  
class testChild extends testParent {
  public function xyz() {
  //body of your function
  }
}


$a = new testChild();
print $a->abc();

1 个答案:

答案 0 :(得分:3)

类的成员可见性有限,但所有类在PHP中基本上都是“公共”。

http://php.net/manual/en/language.oop5.visibility.php

如果您尝试在类上使用public关键字(类似PHP Parse error: syntax error, unexpected 'public' (T_PUBLIC)

,则会出现语法错误