Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122897 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 CF8481A009C for ; Tue, 2 Apr 2024 20:49:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712091008; bh=ilfCXFjivDo43kMGTqY03y0xYMtqAb2nEnYWCx5t8nM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=HoyxVSWUwhnR3P9C5hwnTGx8aT1bnHmdBXAj/dh3/CizANRuTYdJhkXzu7Ez2JRI9 bu73TXdsVZ1V2O3U0P8H/ReoSCrUfdCFY2YLmzRs7+BIFC0doG3WGqct9KJfMLQkLh Hn6zXFznMWRrsFYg2nILpZH10mu41ap1HX9qx8rS9/KMLLEeBalmEnxQDEAvIE0OWK o3q/UjgWD7ZjJ83MGVUpUWg2IUgF4fLzKP0jEQgQlte9a8gWhCocqe0CgPiaR5dyRK D26dFJMoodKEDhnin6d1ibY9EDJksmF+UekxmTRqbGP24ldNox6EndOg7ojERPIpGJ z8KMuUAD3U6Eg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B29691804BC for ; Tue, 2 Apr 2024 20:50:07 +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=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-ua1-f45.google.com (mail-ua1-f45.google.com [209.85.222.45]) (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 ; Tue, 2 Apr 2024 20:50:07 +0000 (UTC) Received: by mail-ua1-f45.google.com with SMTP id a1e0cc1a2514c-7e127d337a4so89488241.0 for ; Tue, 02 Apr 2024 13:49:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712090978; x=1712695778; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=w7T1V5SaHuPLOwW0wFjD4ORPwI/YjdXMP98eo46JYBg=; b=eddPhgmDTPrRg2jYkoMnbWyvPU1KfbVRvr4lFFgaS6eg/6pEX5O/OoyQVNi1m+ZSGn GjFygIzWD+gk+ju8lhVMjzFTD/fC0M7W+IueXwR5mnuGO2ol3mR21B98w+0UBCKvGuTD AyL7jLPc9tt1Tthba7w3LlwdBZici0k6UT5Yk9yzmm1HTQN21ILo3rz7NU0MHVife3TL 01oUhCOG3xNNwU2mnTdWWr93rQdQti/RiUlWgvMa8otB0N96c0bnXpKzz/sZSwa5Sr2T +5n5wx8ECMBcbrH+IlWKmxd1WKkpFsPSrWDzJ6NEUa/bA+idaC6nD7xc6CDN6GjcfPJZ nkjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712090978; x=1712695778; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=w7T1V5SaHuPLOwW0wFjD4ORPwI/YjdXMP98eo46JYBg=; b=PsfaRKeH+9yuPJAzmlgT7bgvIyE42JKZ+mP7680+ZeCmO1mhR8v5imH2qAezhkdAPe I+CEvD0c+lau/M/G/9X5qSMtRmUpfDu6opZwS3jcY0en3buULwkE83ZUOWq4p99k9B/S QmRpW6HPrNMQ9Nrow2JuM6kQ5OZnnsQ7XEeoPk6XyvFXRfa79DMpr4SBmuRDmoBzeKcF xhXfAS8qg+M5d58ACyjOW2Ux1e0+bBDaVQrJQRGjLHneiPf3TT+TY2RvgNke2yuAoLVK wSFijJpS984GuKbbXHemDOoYMa8JgKUc30jDiyO3seJFSO52mVE0l+FBvB1BbSbs0rw7 lVWQ== X-Gm-Message-State: AOJu0YxMNQDECssJhHv2V5DvlSax7/cuTNm9amB11xRzN8Wj8U6Lc1Mw GzWpVCCp7ZX3CGF7XOzFvLDGzhRwcDnfZa3/7C0oUeg0YbsJP2RHSEiz68EeSxb1iRK4g2N06qM ubPS4ec/xiJltFnLCuqrZgMQHQhHj0mPlUgg= X-Google-Smtp-Source: AGHT+IGNVP8s+Ef7SjIcMuvrobU+I4n8J3b4niYP3ZWZ78Mz2W6d6lIRhbhOQ8s5bqWgT2aQ2V3OHhQgaxih1s2YuRc= X-Received: by 2002:a05:6122:251c:b0:4d4:131e:299d with SMTP id cl28-20020a056122251c00b004d4131e299dmr9825667vkb.1.1712090978247; Tue, 02 Apr 2024 13:49:38 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <1a4a44c5-d4f5-40ca-b3dc-13d64c2b4425@app.fastmail.com> In-Reply-To: <1a4a44c5-d4f5-40ca-b3dc-13d64c2b4425@app.fastmail.com> Date: Tue, 2 Apr 2024 17:49:02 -0300 Message-ID: Subject: Re: [PHP-DEV] [RFC][Concept] Data classes (a.k.a. structs) To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="00000000000094ef980615233e87" From: deleugyn@gmail.com (Deleu) --00000000000094ef980615233e87 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Apr 2, 2024 at 1:47=E2=80=AFPM Larry Garfield wrote: > > * Data classes protect from interior mutability. More concretely, > > mutating nested data objects stored in a `readonly` property is not > > legal, whereas it would be if they were ordinary objects. > > * In the future, it should be possible to allow using data classes in > > `SplObjectStorage`. However, because hashing is complex, this will be > > postponed to a separate RFC. > > Would data class properties only be allowed to be other data classes, or > could they hold a non-data class? My knee jerk response is they should b= e > data classes all the way down; the only counter-argument I can think of i= t > would be how much existing code is out there that is a "data class" in al= l > but name. I still fear someone adding a DB connection object to a data > class and everything going to hell, though. :-) > If there is a class made up of 90% data struct and 10% non-data struct, the 90% could be extracted into a true data struct and be referenced in the existing regular class, making it even more organized in terms of establishing what's "data" and what's "service". I would really favor making it "data class" all the way down. I understand you disagree with the argument against inheritance, but to me the same logic applies here. Making it data class only allows for lifting the restriction in the future, if necessary (requiring another RFC vote). Making it mixed on version 1 means that support for the mixture of them can never be undone. --=20 Marco Deleu --00000000000094ef980615233e87 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Tue, Apr 2, 2024 at 1:47=E2=80=AFP= M Larry Garfield <larry@garfie= ldtech.com> wrote:
> * Data classes protect from interior mutability. More concr= etely,
> mutating nested data objects stored in a `readonly` property is not > legal, whereas it would be if they were ordinary objects.
> * In the future, it should be possible to allow using data classes in<= br> > `SplObjectStorage`. However, because hashing is complex, this will be<= br> > postponed to a separate RFC.

Would data class properties only be allowed to be other data classes, or co= uld they hold a non-data class?=C2=A0 My knee jerk response is they should = be data classes all the way down; the only counter-argument I can think of = it would be how much existing code is out there that is a "data class&= quot; in all but name.=C2=A0 I still fear someone adding a DB connection ob= ject to a data class and everything going to hell, though. :-)

If there is a class made up of 90% data struct and = 10% non-data struct, the 90% could be extracted into a true data struct and= be referenced in the existing regular class, making it even more organized= in terms of establishing what's "data" and what's "= service". I would really favor making it "data class" all th= e way down.

I understand you disagree with the arg= ument against inheritance, but to me the same logic applies here. Making it= data class only allows for lifting the restriction in the future, if neces= sary (requiring another RFC vote). Making it mixed on version 1 means that = support for the mixture of them can never be undone.=C2=A0


--
Marco Deleu
--00000000000094ef980615233e87--