Web Development

Object Oriented Programming with PHP

Object Oriented Programming with PHP

Object orientated programming (OOP) is a commonly used term when discussing modern programming techniques. One of the things that makes humans stand out is the ability to categorise – we put objects into categories of similar type of function. For example, we have the category vechicle. Within this category, you have the different types of vehicle – car, bug, train, van. In the same bag, a llama is a type of animal. This analogy applies to programming – we create functions to do specific tasks and then group similar functions into classes. No only does this organise everything, but also allows a common access point for these similar functions.

OOP is a relatively new type of programming as far as PHP is concerned. PHP4 does not provide the full facilities a fully object orientated language such as a C++ provides as standard; but PHP5 improves upon this with much more OOP support. Olate Download 2.2 was programmed in a function based style with no classes at all. However, Olate Download 3.0 rewrites the entire application using classes. This allows updates to be made to the class functions without affecting the main code – you don’t necessarily need to know how a class/function does it’s job, just how to use that function.

Classes can’t do anything on their own. They must contain class functions, sometimes called methods. You define these functions just as if you were creating any normal function, however, you need to do it within the class structure.

Lets first create a class called cow. This class will then contain the functions of the cow. The first thing you do is to define the class:

About the author

Written by Darren W..

Darren Hedlund is a freelance Web developer, writer, and data analyst. Darren has a degree in Computer Information Science and has spent the last 15 years developing application and environments from hand held, windows, web, virtual science, gaming, artificial intelligence and graphics design.

Darren's coding knowledge ranges from C+, Visual Basic, .NET, PHP, JSP, REXX, KIXX, and many others. His graphical and environmental knowledge stems in Macromedia Flash, 3D studio Max, Curious Labs Poser, Adobe Photoshop, and many others. Darren works in many platforms ranging from database, visual design, and, system development.

If you found this post useful you may also want to check these out:

  1. Do Not Reassign the Object Reference of a Locked Object
  2. Writing Classes in Javascript
  3. Using Variable Referencing
  4. Working with PHP Datatypes
  5. RunTime: High-Performance Programming Techniques on Linux and Windows 2000
  6. Develop Aspect-Oriented Java Applications with Eclipse and AJDT