Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121024 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 8122 invoked from network); 8 Sep 2023 23:09:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Sep 2023 23:09:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 246A2180210 for ; Fri, 8 Sep 2023 16:09:03 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-oo1-f45.google.com (mail-oo1-f45.google.com [209.85.161.45]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 8 Sep 2023 16:08:59 -0700 (PDT) Received: by mail-oo1-f45.google.com with SMTP id 006d021491bc7-573429f5874so1446091eaf.0 for ; Fri, 08 Sep 2023 16:08:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694214538; x=1694819338; darn=lists.php.net; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=8NfU7dYKzBypoxo6wixwrFD2mCi0LsRo4UP9YB0csPA=; b=Y6m0krCVpe2FfGx2HZ9q9As/t3NGJ6ynIKyBeiMzwi9G0aWcWe0kChVWZLPhoC1Cdc FQ9o0ZNPK3TezsZH1vRWF6GXOC+7MjTLyD4lFL3oqY4O2+as0vgB6uo4k4vuNRZe2z/1 qbE9wBxJ88rhi7DXifgOTxp3Ln4Jlrkszjox/vp1WulDXUFjmErPLdJYYhhzkii3UO3K H0SXwxprm0ccPBqqjOz/RiQsLYccVr7xxJz4HcaG8fmqGOTO/PgfxiGCPql358vFxjRa y7hGarDTUf7BAHCAHS57sbgKWDiUV/+lnNlmxjLUhTn0UsfFDyqgg8qFc3OIlD4dMMAW ORfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694214538; x=1694819338; h=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=8NfU7dYKzBypoxo6wixwrFD2mCi0LsRo4UP9YB0csPA=; b=mYs90/GlaMD8QcJdjH2HPGhDxcPDB6O/4UpmSaR78o+uGGpn2Ut5O9BUR6f1I8Uhrr tEFmZFCDWBfAvpWM9Z/Evzx68+LS/Yeo/eZMso698UGJLDlEkMbMk+rWemeCfZEPNFTu lmbZyZ3l1/6DKGjZG0EVqHr0c69eCX7zZ8cMvkuLYz7J+kl8fUBWEkMjRHwAhtI6HlHC hrg8mn8XhgOcu69jPAwhtb6dhUJRnZTKLDCslycj4eqZXBtCcK+woAFggPPiE701xY0x Vynhg1BhOpw01/4xyy8BH/HTwQMsuK2FrzmfkEK+ho3cv57BTLByt6+J9Duo0CLH/t7a Fn2w== X-Gm-Message-State: AOJu0YwGDMNL7S5yDshBBEx4LfkxZjhvruqgt403j9Y9GE7c4MkQTSC4 VGYBwNjHKsg8l17qPY56fDIQMjs4INXFH0Ud/xNiAiC0 X-Google-Smtp-Source: AGHT+IHtX3dyEaSOdG3Uypjpc569ehraobmJT2Zad7T+YJJc78hZ6cvynUsGhyZaBx8VVVT21yhsbqbvIQ6u00+6+gc= X-Received: by 2002:a05:6870:3910:b0:1be:f7d9:c0e2 with SMTP id b16-20020a056870391000b001bef7d9c0e2mr4415457oap.38.1694214538358; Fri, 08 Sep 2023 16:08:58 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 9 Sep 2023 00:08:47 +0100 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000bb746e0604e10f91" Subject: Re: [PHP-DEV] RFC Proposal: Readonly Structs in PHP From: davidgebler@gmail.com (David Gebler) --000000000000bb746e0604e10f91 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Sep 8, 2023 at 2:12=E2=80=AFPM Lanre Waju wrote: > Dear PHP Internals, > > I am writing to propose a new feature for PHP that introduces the > concept of structs. This feature aims to provide a more concise and > expressive way to define and work with immutable data structures. Below > is a detailed description of the proposed syntax, usage, and behavior. > > Syntax > > struct Data > { > string $title; > Status $status; > ?DateTimeImmutable $publishedAt =3D null; > } > The Data struct is essentially represented as a readonly class with a > constructor as follows: > > > readonly class Data > { > public function __construct( > public string $title, > public Status $status, > public ?DateTimeImmutable $publishedAt =3D null, > ) {} > } > These as the most basic examples of what you're proposing are barely different expressions in length, let alone anything else. I wouldn't say the first example is particularly more helpful, more readable, more concise or conceptually more expressive than the second. The rest of your examples are similarly either very minor savings of a few characters shaved off here and there, or just as verbose as instantiating a class with a constructor anyway. I'm not convinced by the rationale that this would be a new feature worthwhile for improved expression or concision. I can see a potential benefit in these "structs" (not sure that's the term//keyword I'd choose, given it has different meanings in other languages) though, as a kind of template for properly structured arrays, with a built-in ability to cast them to arrays or treat them as arrays/iterables. This would potentially help give some of the power we're missing by not having generics. So it wouldn't just be equivalent to a shorthand for a readonly class with a constructor, but one which also satisfied a couple of interfaces with the implementation automatically provided. That's my initial reaction/two cents. -Dave --000000000000bb746e0604e10f91--