Preparing for PHP ZCE exam : Chapter #7 OOP

Object Oriented Programming

Most of the rules mentioned in this chapter apply to a great majority of programming languages, so assuming you have some experience with software this should be just a good reminder. Although this chapter has some general ideas of programming there are some PHP specific issues here and there. Take a good look at this one because it is filled with tricky questions. Some topics that are worth mentioning:

Reflections

Reflections are a good tool to investigate your classes or dynamically modify them. This is very often used to create documentation files from a set of PHP classes. The main advantage of reflections is that you can handle dynamic method calling in an elegant way. On top of that you can set static properties in classes and modify the accessibility of fields. This is a powerful tool for dynamic definition of code.

Autoloading

Try to learn everything about the autoloader mechanism. How does it work and how to modify it. There is a good example of autoloading on Wayne May’s blog.

Late Static Binding

This is a new feature in PHP 5.3 and it is a one that was needed for a long time indeed. Now when you call an inherited method of class you can call static methods from the initialy called class rather than parent class with the use of static:: - for examples see the PHP manaul.

Inheritance

Focus especially on questions concerning method overriding. This ones are ment to be tricky with all the variations of overriding. Think of all the abstract/static method modifiers possibilities. Keep in mind that code leading to fatal errors may come up in questions as well.

Magic Methods

Although they are not used often magic methods are key feature of some PHP frameworks. For example Symfony 1.x used them extensively in many aspects. So if you feel like designing a new big project/framework you can consider them as a tool for you. Keep in mind that the current trend is to “get rid of all the magic” as the code is not always clear. More on magic methods can be found on NetTuts+ post

SPL

Standard PHP Library is library of interfaces that provide software developers to finally write PHP code in an object oriented manner. It comes with all sort of Iterators and classes that help construct object with array-like behaviour. I recommend reading this very good introduction to SPL that is available on Zend’s DevZone.

Leave a Reply