MApp uses $database_object. I got an error that I could not use it because it was private. However I changed it to protected and now it works. Note that in the class hierarchy MApp is above MAppAMAdder.
I thought that protected meant that child classes could use the resource not parent classes. Is PHP different from other languages or is my understanding of how inheritance works not correct?
MAppAdder Snippet
class MAppAMAdder extends MApp
{
protected $database_object; // private will cause a fail.
MApp
abstract class MApp extends M
{
protected function getID($pipe)
{
$temp = $this->database_object->_pdoQuery('single', 'pull_id_by_h_token',
array($pipe['server']['smalls']['h_token']));
$pipe['id'] = $temp['id'];
return $pipe;
}
protected function addTweetTop($pipe, $comment)
{
$input = array( $pipe['server']['smalls']['h_token'],
$pipe['server']['smalls']['picture'],
$pipe['server']['smalls']['name'],
$comment,
time(),
$pipe['server']['smalls']['h_file'] );
$this->database_object->_pdoQuery( 'none', 'tweet_insert', $input);
return $pipe;
}
}
Error
Fatal error: Cannot access private property MAppTweet::$database_object in…
In PHP
protectedmeans that parent classes can also access the property:You are correct in that this behavior is different from the “classical” behavior of strongly typed languages such as C++ and Java. In such languages (commonly called statically typed) the compiler prevents you from accessing class members in a way that is not provably correct by issuing a compile-time error. That’s why a parent class cannot speculatively access a member defined in a child class: there is no guarantee that the member will be there at runtime.
On the other hand, PHP is dynamically typed and does let you refer to any member, even ones that do not exist at all (the access results to
nullin that case). The check for the existence of such a member is performed at runtime and can result in a wide array of outcomes (from nothing out of the ordinary to a runtime error in certain cases).