Object design and complete programs

Inheritance, interfaces and traits, exceptions, and a complete program.

About 4 hours of study

Learning objectives

Lessons

  1. 1

    Inheritance, interfaces and traits Intermediate

    Parent and child classes, abstract classes, interfaces, polymorphism and traits.

  2. 2

    Exceptions Intermediate

    Reporting and handling errors with throw, try, catch and finally, and writing your own exception classes.

  3. 3

    Putting it together Intermediate

    Planning and writing a complete command-line program that reads commands, keeps data in a class and reports errors with exceptions.

Module practice

Module quiz

1. How many parent classes can a PHP class extend?
2. Which block always runs, with or without an exception?
3. What must a class do when it implements an interface?
4. Which error does intdiv(5, 0) throw?
5. Why is each command of a command loop wrapped in try and catch?
6. What can a trait do that a parent class cannot?

‹ Closures, built-in functions and objectsFinal assessment ›