Knowledge7

The Linux and Mobile Solution Provider

  • About
  • Training
  • Services
  • Clients
  • In the news
  • Blog
  • Contact Us
You are here: Home / Topic / Object-Oriented Programming

Object-Oriented Programming

This topic is part of our Object-Oriented Programming in PHP training

When version 5.0 was released in 2004, PHP became a full-fledged Object-Oriented Programming Language (similar to Java and C#).

Exercises

We will implement a web application which manages people, dogs and cars in a number of steps until we have explored the most important object-oriented constructs found in PHP5:

  1. Implement the Person and Dog classes (+ required constructors, methods, attributes) and instantiate one object from each class.
  2. Add visibility constructs (private for attributes / public for methods).
  3. Add the Car class with its association as shown in the above diagram. Given that PHP is dynamically typed, what is the risk here?
  4. Use type hints to prevent type mismatch.
  5. Implement the Nameable interface as well as the Nameables class (use an array to hold references). Implement getNames() using foreach(). Use type hints to prevent type mismatch.
  6. Use an exceptions for error handling when someone attempts to create a Car with no number.
  7. Replace the exception by a custom exception.
  8. Use inheritance (sparingly) to create a specialized version of Person called Doctor with a special behaviour for getName().
  9. Replace the array in Nameables by a SplDoublyLinkedList of the Standard PHP library.
  10. Use mktime to make sure that each Car created has a registration date of 25 December 2010 at 10:00
  11. Use strtotime to make sure that each Car created has a first servicing date which is next Saturday at 10:00.
  12. Use strtotime to make sure that each Car created has a second servicing date which is exactly three months after the first one.
  13. Use a static attribute which are shared among all Cars to keep a count of all Cars which have been instantiated.
This topic is part of our Object-Oriented Programming in PHP training

Our forthcoming training courses

  • No training courses are scheduled.

Leave a Reply

Your email address will not be published. Required fields are marked *

Looking for something?

Want to know more?

Get our newsletter

Discover the latest news, tips and tricks on Linux, the Web and Mobile technologies every week for FREE

This work is licensed by Knowledge7 under an Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) license.

The Knowledge7 machine is currently learning and, when activities will resume in the future, things will be quite different. All training and consulting activities of Knowledge7 have been put on hold.