Skip to Main Content
Upgrading to PHP 5
book

Upgrading to PHP 5

by Adam Trachtenberg
July 2004
Intermediate to advanced content levelIntermediate to advanced
350 pages
10h 9m
English
O'Reilly Media, Inc.
Content preview from Upgrading to PHP 5

Chapter 10. PHP 5 in Action

Previous chapters demonstrate individual pieces of PHP 5, but this chapter is different. Instead of presenting new material, it combines together multiple features of PHP 5 into a unified program.

Specifically, I present a simple address book application that allows you to add new people and search for existing people. This application is designed to:

  • Demonstrate a wide range of new PHP 5 features

  • Work completely, even though it’s limited in scope

  • Be accessible both over the web and from the command line

  • Separate application and presentation logic

Records are limited to first name, last name, and email address, and are stored in an SQLite database. A record can be turned into a Person object, and multiple Persons are stored in an addressBook object.

Since the application needs to work from both the Web and from the command line, you need an easy way to convert records into both HTML and plain text. To facilitate this task, every object is capable of using DOM to create an XML representation of its contents. You then use SimpleXML to manipulate these XML documents into formatted output.

The first section in this chapter covers the database schema, so you know how the records are stored. Parts two and three cover the Person and addressBook classes. These sections use many of PHP 5’s new object-oriented features, including property overloading, visibility, class type hints, and custom object iterators using the IteratorAggregate interface. The classes also create, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Expert PHP and MySQL®

Expert PHP and MySQL®

Andrew Curioso, Ronald Bradford, Patrick Galbraith
Pro PHP Programming

Pro PHP Programming

Peter MacIntyre, Brian Danchilla, Mladen Gogala
Mastering PHP 7

Mastering PHP 7

Branko Ajzele

Publisher Resources

ISBN: 0596006365Supplemental ContentCatalog PageErrata