Class Wither Method¶
with is a prefix, that tells the reader that the method returns a copy of the object, and not the object itself. The with prefix may be added to any property name, virtual or concrete.
<?php
class x {
private A $property;
// getter
public function getProperty() : A {
return $this->property;
}
// wither
public function withProperty() : A{
return clone $this->property;
}
}
?>
See also 0 <`RFC: Accessors>`_.
Related : Class, Class Setter Method, Class Getter Method, Immutable