Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120205 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 95247 invoked from network); 6 May 2023 16:45:34 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 May 2023 16:45:34 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id ADA161804AA for ; Sat, 6 May 2023 09:45:32 -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-oa1-f53.google.com (mail-oa1-f53.google.com [209.85.160.53]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 6 May 2023 09:45:32 -0700 (PDT) Received: by mail-oa1-f53.google.com with SMTP id 586e51a60fabf-1928eee97f7so2535211fac.2 for ; Sat, 06 May 2023 09:45:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683391531; x=1685983531; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=nolU7QULBfrhkjF6Dtd17RB0z5wf1EjhGym1nSPLtCQ=; b=PFk9fBYdd7usZqqDO/hZw6iItJtvnA8vDmhrMAd2b63NwEztWJcAc4oR99KFD/KQHs VrFCcNgUgoOEbKitGW+zcd5BpX+sUvi6cXqgF6LeBfD4TdHoT5pNM7J1wVcoybHEo/dG uaxg6yY5MwTKf26PdN4tMjw+PyKSVMUzmrChS3+acQSMzAK6QNa1T59AF6/R3mMrmAWz K3x+kntg5yt7dcirD34ONDwaLIQrU3Rpc5gQ1iXOXzUiUAGs2ov+kufw+HSE5k2271SX WD63S2FKN3mc/8DF3JahozYdqvnpZ/mOx5258WGtGurJDJ60Ia5SRzrj91cgU8dPP4k2 PUYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683391531; x=1685983531; 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=nolU7QULBfrhkjF6Dtd17RB0z5wf1EjhGym1nSPLtCQ=; b=F61EBekudWGrSX1S50RZlavVKhxCtrdKkbbG4AabLhkdsNf1Lg4RA+1HoZpwbxUnOp 5Yvv5iLVdvMKb3ryMLcbpUpiOJ009iv8IDExj1t+jcmc276inU73ujZaEGqNivMDgny+ Kv785OddrDQy5CZjgQ1gUGijjt0+DxkxUJJEsTJ9KnR/hdjDpucse70D91FEy9y/GRNt HE1rKEryEQ/48dgRC0WFeUWtMF7fV3EEfRsT4Hjut9uZh0Hed5U/0PK3IMD0k1+3e+Vp hhczxm70CrJAOvifGVBUugWzZwwA5CrtjP4yQ/aWSiEBQY8+96z7CDMfRk6WiqPeQ26Q SKQA== X-Gm-Message-State: AC+VfDysFU1GN8XO5Z20cQ0wSaGog3AgSZ09QNWPQftkdREkPJWgVkS9 3GovQIY3O6g8eR9edYd78ZV9tlb89tS42F8Fm7Y= X-Google-Smtp-Source: ACHHUZ7M9/0uH2Tu67mRt8FDgO1BIz58D9FnUZfCh6iouf43loMhOEFvh8GdFIz9pFALoKveKIFyccSEjV4uy4ce7Q8= X-Received: by 2002:a05:6870:1aab:b0:18f:4897:e562 with SMTP id ef43-20020a0568701aab00b0018f4897e562mr2329244oab.2.1683391531302; Sat, 06 May 2023 09:45:31 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 6 May 2023 19:45:20 +0300 Message-ID: To: =?UTF-8?Q?Olle_H=C3=A4rstedt?= Cc: internals Content-Type: multipart/alternative; boundary="0000000000003dc4ce05fb092271" Subject: Re: [PHP-DEV] Limit write access to object function parameters From: lokrain@gmail.com (Lokrain) --0000000000003dc4ce05fb092271 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hey there, Looking at how to achieve =E2=80=9Creadonly input object=E2=80=9D now a few= things come in my mind: * Write a readonly class in first place, assuming it=E2=80=99s not a class= from a package you cannot or don=E2=80=99t want to update * Clone the object * Use a new immutable DTO for data transfer * Use stateless =E2=80=9Cservices=E2=80=9D (DI-ed) * Use static code analysers * Have conversations in your team Having this in mind, such feature looks more or less as syntax sugar with not much value. Nevertheless, I like it :) Hope to see other comments. Regards, Dimitar On Sat, 6 May 2023 at 13:55, Olle H=C3=A4rstedt wr= ote: > Heyo internalitos, > > I was thinking of having the possibility to use `readonly` (or any > other keyword) to make a function argument behave as if it was a > readonly object. > > class Point > { > public int $x; > public int $y; > } > function doThing(readonly Point $p) > { > $p->x =3D 10; // Not allowed > } > > In C# it's called in/out/ref types: > https://www.pluralsight.com/guides/csharp-in-out-ref-parameters > > The main use-case is to not give away more access than you have to, > and being able to state your intent in the function signature. > > Another alternative would be to allow properties in interfaces, and > then define a readonly-like interface: > > interface ReadonlyPoint > { > public readonly int $x; > public readonly int $y; > } > function doThing(ReadonlyPoint $p) > { > $p->x =3D 10; // Not allowed > } > > No idea about practical feasability. > > Since arrays are value types, they're not really relevant for this > suggestion. Same goes for string, int, etc. > > Regards > Olle > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --0000000000003dc4ce05fb092271--