Home arrow PHP arrow Building Object-Oriented Web Pages with Inheritance in PHP 5

Building Object-Oriented Web Pages with Inheritance in PHP 5

You have probably used the principles of inheritance in any number of your object-oriented programming projects. Traditionally this means working with parent and child classes during the creation of a PHP application. In this two-part series, you'll learn a simple way to use inheritance while creating object-oriented web pages.

TABLE OF CONTENTS:
  1. Building Object-Oriented Web Pages with Inheritance in PHP 5
  2. Establishing a basic class hierarchy
  3. Using inheritance to derive a web page generator class
  4. Building another web page for a fictional web site
By: Alejandro Gervasio
Rating: starstarstarstarstar / 12
July 16, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Introduction

As the clever PHP developer that you surely are, it's quite probable that you've already used the object-oriented paradigm to develop one or more web applications. This implies that defining a few classes along with their methods and properties should be a pretty familiar procedure to you. Definitely, it must be admitted that building object-based applications with a friendly scripting language like PHP is not only a truly educational experience, since it requires at least a basic knowledge of software engineering, but fun as well. 

As you possibly know, after a decent time working with this approachable -- yet mature -- web development language, it's possible to create scripts that implement a certain level of complexity, particularly when it comes to defining different relationships between several objects. And now that I mentioned the term "relationship," I'm pretty sure that you'll be familiar with the two main pillars of this huge area of object-oriented programming. I mean aggregation and composition.

However, while learning to aggregate and compose classes with PHP (or any other programming language, naturally) can be a significant step toward mastering the fundamentals of software development, it's fair to say that these two proven models of object interaction would be rather pointless if inheritance is deliberately left out of the learning process.

Perhaps, at the moment of reading the previous sentence you feel inclined to congratulate yourself, since you have already worked with parent and child classes here and there during the creation of a given PHP application. But one question is in order here: can inheritance be used in some way that is simpler than the traditional one, even with the purpose of doing something as trivial as building dynamic, object-oriented web pages?

To your satisfaction (and mine, of course) the answer to the above question is a resounding yes! Actually, by using the basic principles of inheritance, it's feasible to create entire, consistent-looking web sites, with only a little effort and an intermediate background in object-oriented programming.

So, now that I have introduced this instructive subject, in the two articles in this series I'm going to show you how to build a sample object-based web site from its bare bones structure, by using the encapsulated logic of some parent and child PHP 5 classes. In this way I'll demonstrate how inheritance can be used to tackle a concrete project, such as constructing dynamic web pages.

All right, it's time to move forward and start learning how to utilize a simple classes hierarchy to create an expandable web site. Let's begin now!



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: