Blogs about Object Oriented Programming

Creating immutable objects in PHP

Published on the 27th January, 2019

You may have seen the \DateTimeImmutable class being used, and wondered why is this different from the \DateTime class? I guess it's the same...but immutable, right? Why would I want to use an immutable object? Here's a brief overview. Why use an immutable class? In php, when you pass around an object by assigning it to a variable, you are actually creating another reference to that object, rather than creating another version of it. $person1 = new Person; $person2 = $person1; $person2->s...

Read more...
Divider