Lesson content
Read, practise, then check your understanding
A PHP class extends one parent. Overrides must honor signature and semantic expectations. Final can close a class or method when extension would break invariants.
Practical example
<?php
abstract class Report { abstract public function render(): string; }
final class HtmlReport extends Report {
public function render(): string { return '<article>Safe content</article>'; }
}
Use parent:: only where extension is designed. Protected mutable fields tightly couple descendants; prefer private state. Choose composition for has-a relationships and reusable policy. Inheritance should express real substitutability, not code-copy avoidance.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.