Re: [RFC] [Discussion] Clone with
| From: | Zoltán Fekete | Date: | Mon, 17 Apr 2023 20:13:19 +0000 |
| Subject: | Re: [RFC] [Discussion] Clone with | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-120057@lists.php.net to get a copy of this message | ||
Hey,
> public function withStatus($code, $reasonPhrase = ''): Response
> {
> return clone $this {
> $this->statusCode = $code;
>
> $this->reasonPhrase = $reasonPhrase;
> }
> };
How to refer to any of the properties of the current instance? Let's say
this:
```
class Foo {
protected int $code;
protected string $message;
public function withStatus($code, $message): Foo {
return clone $this {
$this->code = $code; // so far so good
// Which $this->message is what?
$this->message = "cloned: (" . $this->message . ")" .
$message;
}
}
}
```
> Thanks for your efforts and for bringing that up.
> I am curious if possible to implement the feature without using
with«Zþ
> p´I«DHÓIãÔ
> keyword
> it visually could look pretty close to something like an object
initializer
> in the future:
>
> return clone $this {c: 1};
> return new Bar {c: 1};
Similarity is not necessarily always good.
Regards,
Zoltán Fekete