Book Image

Object-Oriented Programming with PHP5

By : Hasin Hayder
Book Image

Object-Oriented Programming with PHP5

By: Hasin Hayder

Overview of this book

<p>Some basic objected-oriented features were added to PHP3; with PHP5 full support for object-oriented programming was added to PHP. Object-oriented programming was basically introduced to ease the development process as well as reduce the time of development by reducing the amount of code needed. OOP can greatly improve the performance of a properly planned and designed program.</p> <p>This book covers all the general concepts of OOP then shows you how to make use of OOP in PHP5, with the aid of an ample number of examples.</p>
Table of Contents (15 chapters)
Object-Oriented Programming with PHP5
Credits
About the Author
About the Reviewers
Introduction
Index

Extending a Class [Inheritance]


One of the greatest features in OOP is that you can extend a class and create a completely new object. The new object can retain all the functionality of the parent object from which it is extended or can override. The new object can also introduce some features. Let's extend our Emailer class and override the sendEmail function so that it can send HTML mails.

<?
class HtmlEmailer extends emailer
{
  public function sendHTMLEmail()
  {
    foreach ($this->recipients as $recipient)
    {
      $headers  = 'MIME-Version: 1.0' . "\r\n";
      $headers .= 'Content-type: text/html; charset=iso-8859-1' . 
                                                           "\r\n";
      $headers .= 'From: {$this->sender}' . "\r\n";
      $result = mail($recipient, $this->subject, $this->body, 
                                                       $headers);
      if ($result) echo "HTML Mail successfully sent to 
                                          ...