When a beginner starts learning object oriented programming they keep being reminded is encapsulation.
Simple one, right? Just throw in a bunch of private/protected properties and write a nice get/set function for each and every one of them and we're done.
Well, this works to some extent. Getters seems pretty harmless. You always need to get the info from the object itself to present it to a user for example.
So we just pass the object to a template and let it retrieve all the needed information to create the output.
On the other hand setters are completely broken. They let us do so evil stuff that we should be really scared.
At least when they are used the most common way we use them. Let's consider this simple example.
$person = new Person('Bob');
We create a person named Bob. We send the object to a notifier that may do something like send an email to Bob or whatever else.
No problem. But what if the notifier object itself calls a method setName() on our person object and sets it to something else?
That's where the problems start because now we can not be sure what exactly would the getName() method return and that is completely crazy.
I've even witnessed a code built on those relations. There was an object flying all over the application and all the other objects called its setter and getter
methods and it somehow worked. But can you imagine debugging, maintaining or extending such a code? It's almost impossible.
All these setter methods would probably make sense if they did not change the state of the current object but they would return cloned object with that new state instead.
That could save a lot of headaches in the long run as it would be completely clear what's happening and where.
So the next time you'll write your fancy class consider the consequences of it being used in some crazy way.
You should probably read something about immutable objects and how to use them to avoid headaches.