On 12/11/2016 10:57 AM, Silvio Marijić wrote:
Hi,

Discussion is open for following rfc https://wiki.php.net/rfc/immutability

Cheers


Some grammar issues:

"After object is constructor" => should be "After the object's constructor has run".

" If immutable property contains object, to preserve immutability, object that is beeing assigned to immutable property must also immutable." => "If an immutable property contains an object, then in order to preserve immutability the object being assigned must be of an immutable class."

The File class/resource example should note that the last line in it will create a fatal error, as the earlier examples do. It's not clear that the example is an invalid one.

In a few places, "If immutable property..." should be "If an immutable property..." There's several places where articles (the, an, etc.) are missing.

"Notice in above examples removing getters and setting properties to public is optional. They simply doesn't need to be protected anymore in fact that immutable class objects are deeply frozen with eceptions on write." => "Notice in the above examples that removing getters and setting properties to public are optional. They simply don't need to be protected given the fact that immutable class objects are frozen on write." (Several grammar fixes, plus it's a fatal error, not an exception.)

Content issues:

Currently the only "unlocked context" for an object is its constructor. As discussed previously, that is insufficient. For any non-trivial object (more than 1-3 internal properties) creating a new one via the constructor only when incrementally building is prohibitively difficult. The pattern of with*() methods that spawn new objects via clone(), a la PSR-7, needs to be supported. That is:

immutable class Money {
  // ...

  public function add(Money $other) : Money {
    $new = clone($this);
    $new->amount += $other->amount;
    return $new;
  }
}

I'm not sure how easily we can denote that sort of case. It's outside the __clone() function itself, which is what makes it difficult. Without that, though, such immutable objects are of only limited use.

--Larry Garfield

Reply via email to