PHP Object-Oriented Solutions
This book covers object oriented programming within PHP. To avoid confusion between what does work and what doesn't work, all the exercises are hosted on the school's servers.
The exercises on this page are displayed in reverse order of completion.
Posted Exercises
Chapter 9
- Generating the XML for the
<item>
Elements - The script takes information from a database and turns it into an RSS feed, which is a specific type of XML file. Some browsers will ask you to subscribe to the feed instead of just showing it to you.
Chapter 8
- Using the
Pos_XmlExporter
Class - The script is supposed to take the results from a query and put it into an XML document. The script is non-function because of server permissions.
- Using
XMLWriter
to Generate the Output - The script uses procedural code to create an XML file. Because of write permissions, the script doesn't really work, so I've included the output of the script.
- Testing the Database Classes
- The script tests the classes that connect to a database and displays results from it using
LimitIterator
.
Chapter 7
- Creating a Price Filter
- The price filter is a class which extends
FilterIterator
. The page displays only those books which have a paperback version and are less than $40.00. - Understanding the Iterator Interface
- The page displays the result of a script which uses all five methods of the iterator interface to iterate through an array and display the elements within.
- Reading and Writing Files with SplFileObject
- The page displays the contents of three .TXT files which are contained within a subfolder.
- Finding Files of a Particular Type
- The page displays all the files with a .XML extension in the current directory.
- Using Anonymous Iterators as Shorthand
Part 1 | Part 2 - The page displays a script which calls limited information from two separate XML files. The second script uses a more succinct method of calling the XML files, combining them, and limiting the results.
- Applying the Regular Expression to the Element Keys
- The page displays various ways of using regualr expressions with the array being used shown to the right.
- Filtering a Loop with a Regular Expression
- The first part just loads and loops through an XML file, while limiting the results. The second uses the same XML file, but only shows those titles and descriptions where "PHP" appears in the title.
Chapter 6
- Registering Namespaces to Work with XPath
- The page displays various ways to access data through namespaces and XPath.
- Displaying a News Feed
- On a server where write permissions are enabled, the script saves a news feed into a local XML file and then displays the content in a more human-friendly format.
- Outputting and Saving
SimpleXMLElement
Objects - The exercise is supposed to output the second object in the file to a new file and save it under a new name. Because of server permissions, the file will not work online.
- Displaying Book Details
- The page displays the information in a web-friendly format. I altered the code which displays multiple authors to use commas for each, instead of an ampersand (&) for the final author.
- Accessing Unknown Nodes
- The page displays the data in an XML file by accessing it with multiple
foreach
loops. The first two nodes ("node name" and "attribute") are accessed directly while the following nodes are displayed by looping through the remaining node's children without calling them by name.
Chapter 5
- The
RemoteConnector
class - The page displays my class website and accesses it using the custom class.
Chapter 4
- Validating Form Input
- The form is validated using the custom Validate class created throughout the chapter. If data is filled out incorrectly, the page returns with descriptive warnings.
- Filtering Multiple Variables
- The page displays examples of all the variataions of filtering, as well as the arrays created to flag the data.
- Testing Other Filter Contstants
- The form displays the filters that can be applied to
filter_var()
and how they work with various inputs. The array for the dropdown is also displayed. - Checking that a Variable Contains a Number
- The page displays a few ways to use filters with
filter_var()
. - Displaying the
filter_list()
array - The page displays the array contained within
filter_list()
.
Chapter 3
- Using a custom
Date
Class - The page displays the various methods and functionalities of the class.
- Using the
DateTimeZone
Class - the Exercise displays various time zones. The final two are coded in a better way to display multiple time zones at once.
- Examining the
DateTimeZone
class - The exercise uses the
ReflectionClass
constructor to view theDateTimeZone
class. The code has been wrapped in<pre>
tags for readability. - Using the
DateTime
Class - The exercise displays different ways to use the
DateTime
class, as well as displaying some constants. - Examining the Built-in Date-related Classes
- The exercise uses the
ReflectionClass
constructor to view theDateTime
class. The code has been wrapped in<pre>
tags for readability.
Chapter 2
- Throwing and Catching an Exception
- The page shows what the various methods of showing an exception display when called.
- Accessing Methods Automatically
- The method demonstrated will make sure the method exists, then runs it if it proves true.
- Experimenting with Type Hinting
- This exercise explains how to use type hinting. In the first instance (not shown), the type hinting was limited to the
Book
class. When the DVD was added, it though a fatal error. In the second instance (shown), the type hinting is expanded to theProduct
class, allowing all its subclasses to be used. - Creating static properties and methods
- This exercises shows how static elements can be manipulated. The static variable is set to 0, but when the class is called, the number is increased by one. In the exercise, the first instance is set to 1 and the second is set to 2.
- Using class constraints for properties
- The exercise shows two constrains. As ClassB is a child of ClassA, the constraint has been overwritten.