Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120203 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 74582 invoked from network); 6 May 2023 10:55:15 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 May 2023 10:55:15 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9EE481804AC for ; Sat, 6 May 2023 03:55:11 -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=0.6 required=5.0 tests=BAYES_50,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-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (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 03:55:07 -0700 (PDT) Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-2ad1ba5dff7so2426771fa.3 for ; Sat, 06 May 2023 03:55:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683370506; x=1685962506; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=UGnJbuItSMopTrNLw39OXbaYJZguUvXBzpBkSco1xMU=; b=AD0mKJ2KMH0A4NE74QTxJKGhJRVqW8INz7J3ZrSLadIRqc2ogXXyZxGvH6lqdL+fkD jUiaDztfR6/REi9OU8jV+SXXwxRhYFSRuyzetWdH2IPJgVummguYV4IQEVFGsuX4YNnF Y5s+Nitwq8lVfht8ltZ1tZ3X4KkzybSLuVx3JlWBFwhBBGn9PAHq1/DTabqolSmhf6mM LSV0XJBMaEXnZHg3tcUHJs8qALHRhPNrOK+IaqNbZnfSuyc1IxfFbMfeG0duQluQR5e5 wKk4QPGLWzHfocWtCagoqWwojTi531+3ceeZA0Xs0EffI0QsaOXIcpektzmDz3RGPJ3e ENUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683370506; x=1685962506; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=UGnJbuItSMopTrNLw39OXbaYJZguUvXBzpBkSco1xMU=; b=C8B0SlTgfPCniXFbyBuS/G+G/S6pWfnLaqs/8t5Dy0t2oVSyjWhUGk8NJQzq8j+CSW asKdu3BOQ0/CJFR3va/XbZSYcCU39+PMnTh3pcj1b/Xw7DM/NJjE5EQQGkNcjzg+7WL/ 1FCWlKI/9itkbdHHgokhibpAQ5BeoLl+xhB2xSZlVKbCtHXKby1Ml5mWNLcwBRGcVmVt lL/OQwCaTUKYUalmcFIKJ9BNVWAi/pBI+fCRopsCwR2pX3gmHjaex2IyxgePPHV0JS9E Z8DMExj6gN3ETWUHbb6MBMULZisDkqX/29YtWZfr3tw6aNK0IUeq2VwsSOR/4anCotuG l3Pw== X-Gm-Message-State: AC+VfDwSVu5gcAMKu4Slu75al/cyoi4jFIMYu31scFgstbssC34Xbvwx A8xE5dTRuQLAh2ivBvJa8JX4AWukVW3Pnpv//2RVnWGf X-Google-Smtp-Source: ACHHUZ6SUkX77d1koEKhgVSvfqJ00FZzNB6p5RuxzEHAi7Hu/QwOyOqDRCGXX+hoTs2n9n2ufzoyhe7/QbVTqWCcPLg= X-Received: by 2002:a2e:a405:0:b0:2a7:7d70:6bb with SMTP id p5-20020a2ea405000000b002a77d7006bbmr1277931ljn.2.1683370506029; Sat, 06 May 2023 03:55:06 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a2e:6a10:0:b0:2ac:7d94:77ab with HTTP; Sat, 6 May 2023 03:55:05 -0700 (PDT) Date: Sat, 6 May 2023 12:55:05 +0200 Message-ID: To: internals Content-Type: text/plain; charset="UTF-8" Subject: Limit write access to object function parameters From: olleharstedt@gmail.com (=?UTF-8?Q?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 = 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 = 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