Junior — Middle
Is it possible to declare private methods inside abstract classes?
sobes.tech AI
Answer from AI
Yes, in PHP, it is possible to declare private methods within abstract classes. An abstract class can contain both abstract methods (without implementation) and concrete methods with implementation, including private ones. Private methods are only accessible within the class itself and are not visible to subclasses, which allows encapsulating auxiliary logic.
abstract class Base {
abstract protected function doSomething();
private function helper() {
echo "Helper method";
}
public function run() {
$this->helper();
$this->doSomething();
}
}