Design Patterns

Recently I’ve started posting a small series of OO related articles, they cover the APIE concepts and the SOLID principles, if you haven’t read these yet, I strongly suggest you do. Once you’ve got an understanding of how to write maintainable and extensible code, the next step is learn how to solve common programming problems using design patterns.

Design patterns have been around for decades, they were first defined properly by the Gang of Four (GoF). Since being defined they haven’t changed that much, in fact many patterns haven’t changed at all. Each pattern is placed into a group, based on what it attempts to achieve. These group are, creational, structural, behavioural and concurrent.

There are also architectural patterns, these are similar to design patterns, but they have a broader scope, taking the entire system into account, where a design pattern is more specific to an area of code.

Continue reading

SOLID Development

Since writing this article, I have rewritten it in much more detail.

In my last article I posted about “What is APIE?“, if you haven’t read this yet and don’t know what APIE is, I recommend reading that article first.

Just like APIE states the 4 basic concepts of OOP, SOLID defines 5 OOP principles which you should always follow when writing code. The letters stand for Single responsibility, Open-closed, Liskov substitution, Interface segregation and Dependency inversion. As much as all of these principles help in achieving a maintainable code base, the Open-closed and Interface segregation principles aren’t as useful as the others in my opinion as they’re harder to implement effectively and sometimes don’t give much benefit. Regardless I will explain what you need to know about each of these.

Continue reading

PHPUnit testing singleton dependencies

Unit testing should be simple, but when you have a code base which uses static methods, singletons and a lack of dependency injection, you can run into some serious problems.

The key to writing maintainable and testable code is dependency injection. Without dependency injection, our objects have to rely on systems that may or may not be under our control. We want our unit tests to be executable in an environment which does require a database or a file system or another systems API etc. Dependency injection allows us to provide mocks of these external and frankly irrelevant sources. The mocks will simply tell us what we want to hear and then we can test our own system with this data. Normally we would use PHPUnits getMockBuilder method to create mock objects, this however cannot be used in the case of a singleton for a few reasons:

Continue reading

500 The FastCGI process exited unexpectedly

Recently at work, I’ve came across the error “500 The FastCGI process exited unexpectedly” error code: 0xc0000005, trying to execute a PHP script on an IIS6 and IIS7 server. Knowing how annoying it was to resolve and how many people have the same problem, I thought I would answer your questions.

The problem is caused by excessively requiring more memory than is allocated to your script, which depending on the version of PHP you are running, defaults between 8 and 128 megabytes. To work out how much memory your script is actually using, you should log usage at all points in your script (especially in large loops), this can be done using the functions:

Continue reading