Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126107 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id C4CB71A00BD for ; Thu, 5 Dec 2024 17:58:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1733421311; bh=IKFjmtlERh2r7eKlouCUbNZE6POmuT6e71evRoZZ5cA=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=Bclp73Vxhgn+pplenwYtYnG8LyAZrDctshrq6vM2/RosArryseKA0Hz7ONRTu/9MF SgGGWeW8fu2k1xUIhY1ePgMMcjzVGhA984tBtsxLKRUeSN6TAYvOLlFgAYj/KKDIeC Tbha8agUwmuE487q3T3ehgDEgUX93yF/G+bWecHYbte9vn2Kuhh3m14omK5yAd3fZT 9F7duyNfec5csd0o61MTBalYso2p6nDBqiTcAJETEx2Bm7zIJ/K19IBI5BbSUf8kHi BByJU3vtd4PYnafKZKd8VhFWCB6rvxxWmvvKzwP3xuc575d6YJi2xOKPqkF8ui5PGV B02dOOL9EOPvw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E15E818006A for ; Thu, 5 Dec 2024 17:55:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-b6-smtp.messagingengine.com (fhigh-b6-smtp.messagingengine.com [202.12.124.157]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 5 Dec 2024 17:55:09 +0000 (UTC) Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.stl.internal (Postfix) with ESMTP id 4F4F925401EE; Thu, 5 Dec 2024 12:58:16 -0500 (EST) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-01.internal (MEProxy); Thu, 05 Dec 2024 12:58:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:cc:content-type:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1733421496; x= 1733507896; bh=Vnf4m9IThSycsiTsltXYZ9SIgzuHL1sqTsC6NYsRP3k=; b=F oCW36m/fn37oBc8DyB/8i/HF2ABYtJcEjcIM0sZB8kNaTiQTvWEMCUyQUl+LFobr I6SE3VAmlz5ZcNNVRL8cccyGLYGJ1d0eK9pXYYw9e7muwZr0ckpLpVQGKfonii/5 m/TI6QOWJdOBE2tICSw2nQBDhGXPRfRd5xZB3r0yYBKAO3LbX5hU23aRJNTwjCtQ VaffeKRCGwT59TIy3U1LffpLRYIY8nmuWJz9TeEtgFHN4oQecirKYQHvzCCQFmkv DocIqtb6/2JQFVK9K5/kejjYUjofvAXlZXh+kqI/hWSgHSUAzxHovT7OG3CWVTm/ EWyJ2G1Rbwo64My1JiImw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1733421496; x=1733507896; bh=Vnf4m9IThSycsiTsltXYZ9SIgzuHL1sqTsC 6NYsRP3k=; b=FHZ1jm0PHyOG6MvCL86ZroA8cyWBj9K+kRPSGJMi8T64jdsI+iK s/ZhOdVdPKSpajeBd8LFJBGVj78oji6devgApdw7tGm5wN1SULfv0o0Jw+CyuUyF ky5J4FxZJHimQd7IkD/UvWMO1hIulxXyJgnunGsVcZN2FSC5XJuwqRQdcFSjKojx SEuScGRexNjm+SVbhWyIA/DJJ4MYa08w7ZWmLYIoHyxCPhtcHSlg4MP3y7lT0in+ z9wkLJu5bTPND37M0O0zJmBoD8WJXRrh4+g4/9P2qFBWsnKLl4p9AM3ExbegsvR1 OiBhwrOPy+zmHVOOmIb4m7RxlMePgkD86WQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrieejgddutdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepofggfffhvfevkfgjfhfutgesrgdtreerredtjeen ucfhrhhomhepfdftohgsucfnrghnuggvrhhsfdcuoehrohgssegsohhtthhlvggurdgtoh guvghsqeenucggtffrrghtthgvrhhnpeeiueethedvvdefjefhgfeiheelheehtdfhfeek jefflefgvedvkeduteejjedttdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghspdhnsggprhgtphht thhopeefpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehlrghnuggvrhhsrdhroh gsvghrthesghhmrghilhdrtghomhdprhgtphhtthhopehvohhlohguhihmhihrrdhvohhl hihnvghtshesghhmrghilhdrtghomhdprhgtphhtthhopehinhhtvghrnhgrlhhssehlih hsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id BE53B780068; Thu, 5 Dec 2024 12:58:15 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Thu, 05 Dec 2024 18:57:23 +0100 To: "Volodymyr Volynets" , "Rob Landers" Cc: internals@lists.php.net Message-ID: In-Reply-To: References: Subject: [PHP-DEV] Re: PHP RFC: Records - questions Content-Type: multipart/alternative; boundary=cf13b862e2c3493db2927a6935080ca8 From: rob@bottled.codes ("Rob Landers") --cf13b862e2c3493db2927a6935080ca8 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Thu, Dec 5, 2024, at 18:12, Volodymyr Volynets wrote: > Hi, >=20 > I have a question in regards to the proposed PHP RFC: Records. For fol= lowing snippet: >=20 > record Result(bool $success, array $error, array $data); > $result =3D &Result(false, [], []); > $result->with(success: true)->*with(error: $error + ['Some error'])*->= *with(data: $data + ['user_id' =3D> 777]))*; >=20 > Is this possible to append/merge to existing array properties? Like I = am doing with error. >=20 > Regards > Volodymyr Volynets Hello Volodymyr, Assuming you mean $data and $error to be the record's $data and $error a= rrays respectively? In that case, it would have to be something like thi= s: $result =3D $result->with( success: true,=20 error: $result->error + ['some error'],=20 data: $result->data + ['user_id' =3D> 777], ); This is akin to writing it with an array: $result =3D ['success' =3D> false, 'error' =3D> [], 'data' =3D> []]; $result =3D [ ...$result,=20 'success' =3D> true,=20 'error' =3D> $result['error'] + ['some error'], 'data' =3D> $result['data'] + ['user_id' =3D> 777], ]; =E2=80=94 Rob --cf13b862e2c3493db2927a6935080ca8 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
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(b= ool $success, array $error, array $data);
$result =3D &= ;Result(false, [], []);
$result->with(success: true)-&g= t;with(error: $error + ['Some error'])->with(data: $data + = ['user_id' =3D> 777]));

Is thi= s possible to append/merge to existing array properties? Like I am doing= with error.

=
Regar= ds
Volodymyr Volynets

Hello V= olodymyr,

Assuming you mean $data and $erro= r to be the record's $data and $error arrays respectively? In that case,= it would have to be something like this:

$= result =3D $result->with(
  success: true,
  error: $result->error + ['some error'],
  data: $result->data + ['user_id' =3D> 777],
= );

This is akin to writing it with an array= :

$result =3D ['success' =3D> false, 'er= ror' =3D> [], 'data' =3D> []];
$result =3D [
  ...$result,
  'success' =3D> true, =
  'error' =3D> $result['error'] + ['some error'],=
  'data' =3D> $result['data'] + ['user_id' =3D>= ; 777],
];

=E2=80=94 Rob
--cf13b862e2c3493db2927a6935080ca8--