Download the PHP package sdboyer/frozone without Composer
On this page you can find all versions of the php package sdboyer/frozone. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sdboyer/frozone
More information about sdboyer/frozone
Files in sdboyer/frozone
Package frozone
Short Description Freeze and lock objects. Also makes you 23% more like Samuel L. Jackson.
License MIT
Homepage http://github.com/sdboyer/frozone
Informations about the package frozone
Frozone
Managing state sucks. Frozone is a simple set of interfaces and traits (so, PHP >=5.4) that implement some patterns to make it easier. It facilitates two cases:
- Freezing, in which an object with mutable state is irrevocably locked such that that state cannot be further mutated (from the outside).
- Locking in which an object with mutable state is locked with a key, and that state cannot be mutated until the same key is provided to unlock.
Freezing
Freezing is a one-way operation, initiated by calling the method.
Locking
Locking is a reversible operation, initiated by calling the method with a key, and reversed by calling with the same key.
It is useful if you need to send a mutable object around to other code, but want to restrict mutations for as long as the object is in that context.
FAQ
Reflection can change PHP object state, regardless of visibility. Doesn't that make this pointless?
On a purely functional level, it absolutely does.
On an API design level, even if it's possible for calling code to override the protections provided by Frozone, if your object shouldn't be mutated in a specific context/after a certain point, it's still preferable to provide clear feedback to client code that that's the contract you're providing.
Is object state really worth managing in PHP?
In a lot of older PHP applications, no. Being that in the vast majority of PHP applications' execution environments, state is built from scratch on each request, object state tends to have a lot less meaning. But, as more and more modern PHP applications emerge, certain types of state are being effectively encapsulated in objects. In those cases, it's worth managing.