I am trying to write the following code in PHP
class A {
protected static $comment = "I am A" ;
public static function getComment () {
return self :: $comment;
}
}
class B extends A {
protected static $comment = "I am B" ;
}
echo B::getComment () ; // echoes "I am A"
Shouldn't it return I am B
? In oop PHP does not the child overwrite the parent? Thank you for the clarifications.
== EDIT ==
Also my question is what is the difference then between static and instance because in instance it works:
class A {
protected $comment = "I am A" ;
public function getComment () {
return $this -> comment ;
}
}
class B extends A {
protected $comment = "I am B" ;
}
$B=new B ;
echo $B->getComment();