Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120210 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 47227 invoked from network); 8 May 2023 08:02:01 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 May 2023 08:02:01 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6D94F1804AC for ; Mon, 8 May 2023 01:02:00 -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, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (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 ; Mon, 8 May 2023 01:02:00 -0700 (PDT) Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-2ac7c59665bso48566671fa.3 for ; Mon, 08 May 2023 01:02:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683532918; x=1686124918; h=content-transfer-encoding:to:subject:message-id:date:from :references:in-reply-to:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=MATYOsGp6TLEIH5k0IuXKbIidEfIVdSzSNp83xicjuU=; b=U3u/1k6XtDgc3gpZ5pb7z8h7wbpY74LSEgdOWJluH693NKQ/GWW05p1y503rDFSglA XEawhXuSV/g9hxr4Tl76HdDNAXRt2jN4UVheWJtLveczO9QUeXzrgcTvdUGGFDqonzUt 3cKlu45yw4dz6OD+CD0bjxc8nycCB9u5gshtNXX6LXFrnMI7Ml020lgcgy5SOn6rIlzy t6fmbFyrbiGHMkBAUMkevzDHUIgCr4RPjInqic3vKPpYuvpgMTRNoC5cLbkWdZaeV69s E5HsZYNV4nHf0bWvbUckvpZIRFFR58L7yIbRscRE/9P0XosiHyeWo9n+Ki8d2tA04szx pv8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683532918; x=1686124918; h=content-transfer-encoding:to:subject:message-id:date:from :references:in-reply-to:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MATYOsGp6TLEIH5k0IuXKbIidEfIVdSzSNp83xicjuU=; b=ISlK6ByRYO8u4kyMHJcJYs9wl7AOUJspvsitp/qiz1STfgL7yUGROctKDfvJ0+uhkl Vg2pbMH/Xl4TPrYGs9ANM4pQKxzKI//WcdIqWqPIlUc0U1xOOfrVvK+THiPuSeR4NkAz 09DblCd8DjROFHo0CHdBTvD93Sb9AvPJsB+xFBkqbQmCfoPPo8R3pz3kgwnoZGNFSiEV 5Xwn+HBZxSeMwnI0LWq49v54FbWoVtT1UsMX4B8yimF56uUWwF85FHxxvH/yK0RgH56A aeVZWxU7gA1TP8eh9F+a3DtYfpTxzQdOv2A7pzL1UIrmyQTBct8NNmYGuUWF/WE1ELLW XJpg== X-Gm-Message-State: AC+VfDw9Xg60NQUUhvSVYX0jdxDyOjHhc9uldy1x6EqzvHwSttTTBNUL YNa3Ehgbuw8aGANGlWElxRL4A+kVdrzhU5zGiLtJ2Bc95z5Big== X-Google-Smtp-Source: ACHHUZ5ucFLXzPwc6p6IONllN2QF0VgGnBrz/AsrjbYyNmdrZSMG9kmiWUOk1JngA5bteamdMz9Fd9ybm++9NVkK+Vs= X-Received: by 2002:a2e:9b83:0:b0:2ad:508a:b4b9 with SMTP id z3-20020a2e9b83000000b002ad508ab4b9mr1459844lji.44.1683532918395; Mon, 08 May 2023 01:01:58 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a2e:6a10:0:b0:2ac:7d94:77ab with HTTP; Mon, 8 May 2023 01:01:57 -0700 (PDT) In-Reply-To: References: Date: Mon, 8 May 2023 10:01:57 +0200 Message-ID: To: internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: Limit write access to object function parameters From: olleharstedt@gmail.com (=?UTF-8?Q?Olle_H=C3=A4rstedt?=) 2023-05-06 12:55 GMT+02:00, Olle H=C3=A4rstedt : > 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 Also related is Object.freeze from JS (I was told): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Ob= jects/Object/freeze Olle