11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

www.it-ebooks.infoCHAPTER 6 • OBJECT-ORIENTED <strong>PHP</strong>Key OOP ConceptsThis section introduces key object-oriented implementation concepts, including <strong>PHP</strong>-specific examples.ClassesOur everyday environment consists of countless entities: plants, people, vehicles, food...I could go on forhours just listing them. Each entity is defined by a particular set of characteristics and behaviors thatultimately serves to define the entity for what it is. For example, a vehicle might be defined as havingcharacteristics such as color, number of tires, make, model, and capacity, and having behaviors such asstop, go, turn, and honk horn. In the vocabulary of OOP, such an embodiment of an entity’s definingattributes and behaviors is known as a class.Classes are intended to represent those real-life items that you’d like to manipulate within anapplication. For example, if you want to create an application for managing a public library, you’dprobably want to include classes representing books, magazines, employees, special events, patrons,and anything else that would require oversight. Each of these entities embodies a certain set ofcharacteristics and behaviors, better known in OOP as properties and methods, respectively, that defi<strong>net</strong>he entity as what it is. <strong>PHP</strong>’s generalized class creation syntax follows:class ClassName{// Property declarations defined here// Method declarations defined here}Listing 6-1 depicts a class representing employees.Listing 6-1. Class Creationclass Employee{private $name;private $title;protected $wage;protected function clockIn() {echo "Member $this->name clocked in at ".date("h:i:s");}}protected function clockOut() {echo "Member $this->name clocked out at ".date("h:i:s");}Titled Employee, this class defines three properties, name, title, and wage, in addition to twomethods, clockIn and clockOut. Don’t worry if you’re not familiar with some of the syntax; it willbecome clear later in the chapter.1377

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!