Doctrine 2 and the law of demeter

Tags:

Doctrine 2 makes it very convenient to access related objects in your code: Just do a $entity->getRelatedSomething()->getThingValue(); However, this kind of pattern makes for easy errors when getRelatedSomething returns null – and as a side effect of this, you can end up with a lot of code which checks if the value exists before accessing it. This in turn can …

Exceptions and abstraction

Tags:

So you already know how to handle your errors properly. Even if you’re already using exceptions, there are some nuances to the use of exceptions that are important to know and understand in order to write code that is easier to reuse and more decoupled. Let’s talk about exceptions and how they relate to your classes and abstraction.

What makes an abstraction good, and why should I care?

Tags:

You probably know what abstraction means – making a complex process simpler – but do you know what makes an abstraction good, and why it’s important? If you are writing code for a project that lives a bit longer, or has multiple developers working on it, having a good abstraction matters. Lack of a good and consistent abstraction will reduce …

Practical uses for reflection

Tags:

You may have heard about the reflection feature in PHP. Simply put, it’s a way to get a list of methods in a class, a methods parameters, or other “internal” things like that. But how is this actually useful for any common task in application development?