PHP 5 Advanced OOP and Design Patterns PDF Ebook
In this article, you learn how to use PHP’s more advanced object-oriented capabilities. When you finish reading this chapter, you will have learned:
Overloading capabilities that can be controlled from PHP code
In PHP 5, extensions written in C can overload almost every aspect of the object syntax. It also allows PHP code to overload a limited subset that is most often needed. This section covers the overloading abilities that you can control from your PHP code.
PHP allows overloading of property access and method calls by implementing
special proxy methods that are invoked if the relevant property or method
doesn’t exist. This gives you a lot of flexibility in intercepting these actions and defining your own functionality.
Using design patterns with PHP 5
Some people believe that any language that has objects that encapsulate data and methods can be considered OO. Others would also include polymorphism via inheritance and access modifiers into the definition. The purists would probably list dozens of pages of things they think an OO language must support, such as exceptions, method overloading, reflection, strict typing, and more.
You can bet that none of these people would ever agree with each other because of the diversity of OOP languages, each of them good for certain tasks and not quite as good for others.
However, what most people would agree with is that developing OO software is not only about the syntax and the language features but it is a state of mind. Although there are some professionally written programs in functional languages such as C (for example, PHP), people developing in OO languages tend to give the software design more of an emphasis. One reason might be the fact that OO languages tend to contain features that help in the design phase, but the main reason is probably cultural because the OO community has always put a lot of emphasis on good design.
The new reflection API
New to PHP 5 are its reflection capabilities (also referred to as introspection). These features enable you to gather information about your script at runtime; specifically, you can examine your functions, classes, and more. It also enables you to access such language objects by using the available meta data. In many cases, the fact that PHP enables you to call functions indirectly (using $func(...)) or instantiate classes directly (new $classname(...)) is sufficient. However, in this section, you see that the provided reflection API is more
powerful and gives you a rich set of tools to work directly with your applica-
tion.
The reflection API consists of numerous classes that you can use to introspect your application.The following is a list of these items. The next section gives examples of how to use them.
PHP 5 Advanced OOP and Design Patterns PDF Ebook
Posted in :