7.8.3. Discussion
When you override a parent method by defining one in the child, the
parent method isn't called unless you explicitly
reference it.
In the Solution, we override the draw( ) method in
the child class, circle, because you want to
accept circle specific parameters and validate the data. However, in
this case, we still want to perform the generic shape::draw(
) action, which does the actual drawing, so we call
parent::draw( ) inside your method if
$radius is greater than 0.
The call to parent::$parent( ) may look a little
odd. However, PHP just substitutes in the parent class name for the
$parent variable. Then, because there are
( ) s after the variable, PHP knows it should make
a method call.
It's possible to hardcode the call to
parent::shape( ) directly into the
circle constructor:
function circle( ) {
parent::shape( );
}
However, this isn't as flexible as using
get_parent_class( ). It is faster, so if you know
your object hierarchy isn't going to change, that
may be a trade-off you can benefit from.