I do not understand this particular case or what Alexander says.
class instance is not the same as class?
As already Alexander Larikov said that you can't access protected methods from class instance but not only protected methods but also you can't access private methods from class instance. To access a protected method of a parent class from the instance of a subclass you declare a public method in the subclass and then call the protected method of the parent class from the public method of the subclass, i.e.
ALEXANDERS'S SOLUTION:
class testgiver{
protected function dbConnect($userconnecttype)
{
echo "dbConnect called with the argument ".$userconnecttype ."!";
}
}
class testprinter extends testgiver
{
// WHAAAAAT? WHYYYYY?
public function buildquestionarray() // public instead of private so you can call it from the class instance
{
$this->dbConnect('read');
}
}
$tp=new testprinter();
$tp->buildquestionarray(); // output: dbConnect called with the argument read!
'Fatal error call to private method' but method is protected
why can't I access a protected method from a private method if the protected ones are inherited by the subclasses?
CODE BEFORE SOLUTION:
Line 726 of testprinter in the code below:
private function buildquestionarray()
{
$query = "etc etc";
**$conn = $this->dbConnect('read');
$result = $conn->query($query);
...
Testprinter extends testgiver. Here's the extension of the class:
require_once('testgiver.php');
class testprinter extends testgiver
{...
And the declaration of the method in testgiver:
protected function dbConnect($userconnecttype)
{...