抽象类不能声明为public



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

在抽象

之前添加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();

类的成员可能在可见性上受到限制,但在PHP中所有的类本质上都是'public'。

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

如果您尝试在类(如PHP Parse error: syntax error, unexpected 'public' (T_PUBLIC))上使用public关键字,您将获得语法错误

最新更新