PHP Objects, Patterns and Practice (3rd edition)

(Barry) #1
CHAPTER 5 ■ OBJECT TOOLS

The example assumes that the required object can be instantiated with a single string argument to
its constructor. It’s best, of course, to check this before calling ReflectionClass::
newInstance().
By the time the ModuleRunner::init() method has run its course, the object has a store of Module
objects, all primed with data. The class can now be given a method to loop through the Module objects,
calling execute() on each one.


Summary


In this chapter, I covered some of the techniques and tools that you can use to manage your libraries
and classes. I explored PHP’s new namespace feature. You saw that we can combine include paths,
namespaces, the PEAR class naming convention, and the file system to provide flexible organization for
classes. We examined PHP’s object and class functions, before taking things to the next level with the
powerful Reflection API. Finally, we used the Reflection classes to build a simple example that
illustrates one of the potential uses that Reflection has to offer.

Free download pdf