Re: PHP RFC: Records - questions

From: Date: Thu, 05 Dec 2024 17:57:23 +0000
Subject: Re: PHP RFC: Records - questions
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-126107@lists.php.net to get a copy of this message
On Thu, Dec 5, 2024, at 18:12, Volodymyr Volynets wrote: > Hi, > > I have a question in regards to the proposed PHP RFC: Records. For following snippet: > > record Result(bool $success, array $error, array $data); > $result = &Result(false, [], []); > $result->with(success: true)->*with(error: $error + ['Some > error'])*->*with(data: $data + ['user_id' => 777]))*; > > Is this possible to append/merge to existing array properties? Like I am doing with error. > > Regards > Volodymyr Volynets Hello Volodymyr, Assuming you mean $data and $error to be the record's $data and $error arrays respectively? In that case, it would have to be something like this: $result = $result->with( success: true, error: $result->error + ['some error'], data: $result->data + ['user_id' => 777], ); This is akin to writing it with an array: $result = ['success' => false, 'error' => [], 'data' => []]; $result = [ ...$result, 'success' => true, 'error' => $result['error'] + ['some error'], 'data' => $result['data'] + ['user_id' => 777], ]; — Rob

« previous php.internals (#126107) next »