在PHP的抽象类中可以有一个私有的具体方法吗
TL;DR : yes, you can.
abstract class Foo
{
private function test() {
echo 'abstract private' . PHP_EOL;
}
public function useTest() {
$this->test();
}
}
class Bar extends Foo {}
$x = new Bar;
$x->useTest();
Live example: https://3v4l.org/Efd5Q
But that private method will be visible ONLY to that abstract class. It means, that it will have to be used by some other concrete method within the abstract class (with protected of public visibility).
The child classes won't be able to call it directly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.