Tout d'abord, citons le manuel de PHP ( http://php.net/manual/en/keyword.extends.php ) :
The extended or derived class has all variables and functions of the
base class (this is called 'inheritance' despite the fact that nobody
died) and what you add in the extended definition.
Pourquoi cet exemple simple ne fonctionne-t-il pas ?
<?php
class A
{
private function a()
{
echo 'a';
}
public function b()
{
echo 'b';
}
}
class B extends A
{
//no extended definition, only what's inherited
}
$object_B = new B();
echo $object_B->b(); // fatal error: Call to private A::a() from invalid context
?>
Après quelques expériences, il s'avère que l'élimination des méthode a de la classe A le fait fonctionner. Et je ne l'appelle même pas n'importe où.