Main Content

Learning about Object Orientation in PHP - a new set of examples

Archive - Originally posted on "The Horse's Mouth" - 2013-04-28 08:57:00 - Graham Ellis

I've written a new series of examples to teach Object Oriented Programming in PHP ... taking tables in a restaurant as my example, as we all have to eat. Calculating things like the number of people who can sit at a table (that's not as straightforward as you think) and hiding that calculation in the class code. Adding in round tables as well as rectangular ones, where some calculations vary but other remain the same.

Here is the sequence of examples:
First object / test case example
Using an array of objects
Creating objects from data in file
Using a factory method to make the objects
Objects of different (but similar) types
Comparing objects, converting to strings etc

Tables in a restaurant .. camp sites .. twitter messages .. sales contacts .. helicopters .. web connections .. gas bills .. books .. all of these and just about anything else cn be well handled through an object oriented approach such as the one shown in this series of examples. Each of them will need to have objects set up ("constructed") from data, and each will have values saved in and gotten out ("properties" or "attributes"). Calculations will be necessary on some attributes - these will vary - but many attributes wil be just stored and retreived ...

Our Object Oriented Programming in PHP course covers the techniwuers for designing and writing Object Oriented programming, and covers how you do it in PHP as well. Follow the link to find the upcoming dates!