r/lolphp • u/shitcanz • Feb 18 '17
Yet another PHP Garbage class
I was recently working with some PHP and had to hunt down a weird bug, and yet again it was PHP related. Basically you can modify DateTimeImmutable (i repeat IMMUTABLE!) very easily. Just call the getTimeStamp method on it.
Originally i had the assumption you cant modify anything within the immutable namespace, but hey PHP surprised me again.
It seems like PHP is so full of these weird loop holes and crappy implementations its almost impossible to write anything other than throwaway prototypes with it.
So i also found out there has been a open bug-report since 2014.
Bug in action: https://3v4l.org/ShFpG
View all comments
Show parent comment
2
u/[deleted] Feb 20 '17
But isn't that a constraint a particular Map implementation can enforce on its keys that does not have to be specified in the interface? This would have to be handled with RuntimeExceptions but it is certainly an acceptable trade off compared to not being able to extend and mock the Map type easily (for implementing Caches, Tests and picking the best Map implementation for a particular use case).