Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115447 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 99232 invoked from network); 17 Jul 2021 05:16:15 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Jul 2021 05:16:15 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E28D818033A for ; Fri, 16 Jul 2021 22:40:40 -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_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f171.google.com (mail-yb1-f171.google.com [209.85.219.171]) (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 22:40:40 -0700 (PDT) Received: by mail-yb1-f171.google.com with SMTP id v189so18415299ybg.3 for ; Fri, 16 Jul 2021 22:40:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=sS7ODGpjp3IcnfCFLazpwr4EFfpflEDlvYi4/wsyyqA=; b=BVJm9d6Z0SKg9Z/KMn3yz4kCxfQKDC+921MIn1/hT9Xp4k6QB31/L1MmraxMC83Fp/ 1+T5W1YNSesRZH7IKFiY98tw9JJGXZWweBp2HZSEmOiVfyusbstCPFGlXJ8NbML8ocek Hb4wKp24TJxN2vgnNLt1ojXgyvYGYdkcNMTt5Gpbsr28Y9uQt85G0G4dnlBWqWSUoNPs 1cjYvCK2KvqDlK5KJW8BSaSaemT2/7eDzF+i1TGip1dvUd5KLvDjRbI20+qLa3lKgHJ9 UkmB8Uu8MRbd1woLpxcae0LNSPaINwvScxGiZnnxDpsF6yrhy0sMLMed9RwgyPEuaj+V kz/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=sS7ODGpjp3IcnfCFLazpwr4EFfpflEDlvYi4/wsyyqA=; b=HVos3sObinq0385rDehGZTnOFnvFx3a1VvpWxBwXPuTtwIh0HjgpqIkHyfsosy2q6D iXCZPdRwe92jc2CzrBwYnWmC5e58oL02ulN9qsuCRfnT1D8k0NnyUYynGQ7jOUnOAxQz Fzn924Ziu8SuSJeThKT8lJNA5CcksU1W7MzIhM8q2PZS+2SdZ9pas+sjacmRRZevn/Na CDfL2s4FZhQnfLp7oI4I+ZdhH7NCyjY+0epgwRZvw0AAVwd55YetIy81ADQbnaHAdBgV 7srWHxt84P52843R8b1DYR7PvHeFQ5DTxKqfwgLdUm0/dc5jsnyGCcyjopl7R1JOjajN 1yNQ== X-Gm-Message-State: AOAM533NxgrJFPJvJ4SI7JIuHd92WwHI0C3JGECeg+bjv5RV6RJmTgi3 OF/X9MgooeZGmtqCPeBGukh74un2C4/nOh+CCs8= X-Google-Smtp-Source: ABdhPJyj6srlHzOmvzos6dxMSJBVuD67n/xyFMAfEBtoB9oqljhXnaQ8zqFj8nWGsTcdnFKAfATHBwsh/hHpZAOny74= X-Received: by 2002:a25:f504:: with SMTP id a4mr16630250ybe.170.1626500438937; Fri, 16 Jul 2021 22:40:38 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 17 Jul 2021 08:40:27 +0300 Message-ID: To: Mike Schinkel Cc: Bruce Weirdan , PHP Internals Content-Type: multipart/alternative; boundary="000000000000e3d5b805c74b24ee" Subject: Re: [PHP-DEV] Readonly properties - immutability by default From: zsidelnik@gmail.com (Eugene Sidelnyk) --000000000000e3d5b805c74b24ee Content-Type: text/plain; charset="UTF-8" > 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? We already have such an attribute provided. It is called [`#[Immutable]`]( https://blog.jetbrains.com/phpstorm/2020/10/phpstorm-2020-3-eap-4/#immutable ). If the intention is to add some logic for attributes, then unlikely it is going to be accepted because attributes by definition are meta-data. It doesn't add any logic for program. On Sat, Jul 17, 2021 at 12:09 AM Mike Schinkel wrote: > > On Jul 16, 2021, at 6:12 AM, Bruce Weirdan wrote: > > > > On Fri, Jul 16, 2021 at 9:45 AM Eugene Sidelnyk > wrote: > > > >> 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. > > > > If every property of the class is readonly it would probably be better > > to declare that with a class modifier. > > > > E.g. > > > > ```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. > > -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... > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --000000000000e3d5b805c74b24ee--