mbretter / stk-immutable
Stk Immutable Data objects
Installs: 2 969
Dependents: 4
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.0
- ext-json: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^v3.21.1
- phpstan/phpstan: ^1.10.25
- phpunit/phpunit: ^9
README
This library implements the immutable design pattern for objects holding some kind of data.
Maps
Maps can hold objects (stdClass) and/or arrays, they can be nested, very useful when reading/writing from/to noSQL databases like MongoDB.
use Stk\Immutable\Map; $a = new Map((object)['x' => 'foo', 'y' => 'bar']); $b = $a->set('x', 'whatever');
Calling the set method on the object $a does not modify it, a clone with the modifications is returned instead, the original Map will never be modified.
Comparing two Maps is easy, there is no need for writing complicated and resource consuming comparision functions, simply use the identical operator:
if ($a === $b) { ... }