Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115445 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 74986 invoked from network); 16 Jul 2021 20:44:47 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Jul 2021 20:44:47 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6C0101804AA for ; Fri, 16 Jul 2021 14:09:05 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 16 Jul 2021 14:09:04 -0700 (PDT) Received: by mail-qk1-f173.google.com with SMTP id 77so10042419qkk.11 for ; Fri, 16 Jul 2021 14:09:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=h2fW0XnYij3f0t9VR4bJLX1r19tYfCeEmoNi7Emyjfo=; b=16ptG1xSTuzpVrVopRPHS3UrDdbFN/2eGhZybD556hXVQbGvKsEsur65JyYQ7VxZPY Z5gw0AuRTetPIKDwACDdGJ1wkrixFNtSA1K/LqJsoH2NSw76tIO50ZZbvGVGKJbjXq5V Gsph8e+3gVAJWi3CnUodHAN4CC9aPz/mgLnaI8v3UzBs4nydfb1L7EgamnvSp41GwhaV s+m8o8XvtOzwdZaz8iXBVK225NIvfQetbsNPSN6vaoJUxNPN5+QMIWxIbgS53gUuz5Oy dZunUrwNqT+RwtTl1WHyi8LvCUQ+UuXwumFq2Oq5bBfeWgOiYmpkwOkQQJJTi5/WVWdu Iwzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=h2fW0XnYij3f0t9VR4bJLX1r19tYfCeEmoNi7Emyjfo=; b=R+OsN02CKF7YZ9lUFK/ACfhpQ9Gd1FVQqEvWphjp3G61fjV29T3DIHbLYWRobqHEXh 45Agxi2gwRi9VEXmS2nUpmXK4BCZb4zosyXcW73xiNQyeVnUwCS2Jyf9gXi6qU5up7Lq Ji+Bs7g0fAfq0IBKpWUblP3GRmcakKJAWZEOWIdBdGrfMQjn2PUx8KqjLt34sweQUlU3 sXPo/XCTURh1liVkGUz+O80af5G79CDaLkXGvtDvacDNvnqdOLxcO6CWXql1sREZLg0b 2rTQtqFjskD1OzkL6omMW+Mp5oIGf+w+1ngQSfVUHPlxJIbGtKpuosMBWwVttkY0wwpA pltg== X-Gm-Message-State: AOAM531aGKAzZHJQsIZBrfeGy4MKGkxOwgNLBnaTkTkgn49jhLazpn1w VvLq2Hlh2Orc4v1tk2ba4/v2QA== X-Google-Smtp-Source: ABdhPJzXWj6OuXSiW5NSgqiySAWL8iST3cY6/xbkU6ZBUfjuAwPrg5SafHRoGnCATG3gdgHuQVJSjQ== X-Received: by 2002:a37:9d12:: with SMTP id g18mr11347734qke.457.1626469741917; Fri, 16 Jul 2021 14:09:01 -0700 (PDT) Received: from [192.168.1.10] (c-24-98-254-8.hsd1.ga.comcast.net. [24.98.254.8]) by smtp.gmail.com with ESMTPSA id r4sm3764944qtc.66.2021.07.16.14.09.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Jul 2021 14:09:01 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\)) In-Reply-To: Date: Fri, 16 Jul 2021 17:09:00 -0400 Cc: PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: References: To: Bruce Weirdan X-Mailer: Apple Mail (2.3608.120.23.2.7) Subject: Re: [PHP-DEV] Readonly properties - immutability by default From: mike@newclarity.net (Mike Schinkel) > On Jul 16, 2021, at 6:12 AM, Bruce Weirdan wrote: >=20 > On Fri, Jul 16, 2021 at 9:45 AM Eugene Sidelnyk = wrote: >=20 >> Readonly properties are really useful for DDD, where everything is = going to >> be immutable. It promotes best practices. However for people to use = it, >> syntax should be concise and brief. >=20 > If every property of the class is readonly it would probably be better > to declare that with a class modifier. >=20 > E.g. >=20 > ```php > readonly class Entity { > public int $count; > public string $data; > } > ``` Having a "readonly" class where the properties are read-only by default = makes sense to me, but maybe the better way to do it is with an = attribute? #[Readonly] class Entity { public int $count; public string $data; } OTOH, that would be inconsistent with using `readonly` as a keyword for = properties.=20 -Mike P.S. Maybe readonly properties should be implemented with an attribute = instead of a keyword? But then that would be opening a can of worms...=