website/errors/method.private.md
<?php declare(strict_types = 1);
class Foo
{
private function doFoo(): void
{
}
}
class Bar extends Foo
{
public function doBar(): void
{
$this->doFoo();
}
}
This error is reported in two situations:
Bar tries to call doFoo() which is a private method of Foo.Private visibility means the method can only be called from within the class where it is declared.
If the method should be accessible to child classes, change the visibility to protected:
class Foo
{
- private function doFoo(): void
+ protected function doFoo(): void
{
}
}
If the method should be accessible from anywhere, change it to public:
class Foo
{
- private function doFoo(): void
+ public function doFoo(): void
{
}
}