Closed mnapoli closed 10 years ago
Value objects should be immutable.
So each method should return a new object, different from $this, and should not modify the current instance.
$this
This is particularly true for Array, for example:
Array
public function sort() { sort($this); return $this; }
Should be:
public function sort() { $array = clone $this; $result = sort($array); if ($result === false) { throw new Exception(...); } return $array; }
Thanks, good suggestion. https://github.com/rossriley/php-scalar-objects/commit/a0e38d8126a8dab5399d915b34ea0d0e74ae7cee
I'll make a note to update the other methods too.
Value objects should be immutable.
So each method should return a new object, different from
$this
, and should not modify the current instance.This is particularly true for
Array
, for example:Should be: