Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118361 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 84335 invoked from network); 6 Aug 2022 05:29:37 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Aug 2022 05:29:37 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2A5E0180380 for ; Sat, 6 Aug 2022 00:30:21 -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-yw1-f177.google.com (mail-yw1-f177.google.com [209.85.128.177]) (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 Aug 2022 00:30:17 -0700 (PDT) Received: by mail-yw1-f177.google.com with SMTP id 00721157ae682-31f443e276fso42103817b3.1 for ; Sat, 06 Aug 2022 00:30:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=acB8SqVRi9mksQzj+rLN5Vr99bKVzodqZuy3YHR493M=; b=n+1GhnF+oXI+3l3P2pg19zT/4r8KmOng/QTLiTPuZMQWDYln5cjbO0K2Z6nff6CvTe 7lMiOzIhuGi0BObtKqDfAJP4b2nJpmm+BpxrM/MuVuDrpyq+niK4jdH8UP8vPlAi5aXY nbSv0KPqo7S7qTZOjcqDwLzRm0qlJ+Ck7dpj3SZKPca25+Ran+hs9nFko2ChAhiZNjlP fMIL6eIX1pRpVYPfnhMBZL41do4wKE7AGh06B+HvJDZe49ZOkrjitL/a67HUm9xKV3Z0 LWzIrXfhVQO8NnoU4+dAPBMsT51IQyC3/LtLL3VvWVAKAdGGpC+JgZ5IdiI5xws8zMgk UFaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=acB8SqVRi9mksQzj+rLN5Vr99bKVzodqZuy3YHR493M=; b=GUiy8gSlrN+YJArEJXExu9Q3FF2c6EAoXsuM+gaNgFzGaa5aZ2HYZVvVo81HLHF4IA EUqHfM5UCxgildArBte/4mfYO+00kPoQGPpTu6BD2aX75js9unxxu9ljnNQmmSiZRoV8 Z8wFl9LP0kNViupyUxA55SNxNXzsYYabITmfFInFUmjnzRF3/mCCopdFGAKmKkMzk6uT BpYNmYoMfDt7jL1vdZLs2pXHvOvia5zh8iAGTfRy1Pyf2iCgnShrOC73nPmqp7i3F7FT xWcJV41mzZobJ/9gw26GM1gLVwnmv+qxxavIefsPZpLqXChk7nlHFgzp2vSC4aVr0OW4 2XEQ== X-Gm-Message-State: ACgBeo0m2JfhcrmWhizAS/qwyD5ZczPexs1hoags8TEDDUsQBH2srL0m /0A/A7VVTWpXNGac+jQUSIrsP2bi0snlYvlz1Sk/c5twwzmnkA== X-Google-Smtp-Source: AA6agR5NosXz9GYXSQL8/Pg6rPjuGJovuxl8ofhVDwYaYnD7HL9DeL4k0m3VgGQiNJqjinBZEY3uxR0hePA8+5DxbLI= X-Received: by 2002:a81:6e02:0:b0:321:cce0:b268 with SMTP id j2-20020a816e02000000b00321cce0b268mr9369444ywc.233.1659771016893; Sat, 06 Aug 2022 00:30:16 -0700 (PDT) MIME-Version: 1.0 References: <0923bd88-8e62-4386-bf6b-4ef9456780b4@www.fastmail.com> In-Reply-To: <0923bd88-8e62-4386-bf6b-4ef9456780b4@www.fastmail.com> Date: Sat, 6 Aug 2022 09:30:05 +0200 Message-ID: To: Larry Garfield Cc: php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Asymmetric visibility From: landers.robert@gmail.com (Robert Landers) On Fri, Aug 5, 2022 at 10:25 PM Larry Garfield wro= te: > > On Fri, Aug 5, 2022, at 1:08 PM, Matthew Weier O'Phinney wrote: > > On Fri, Aug 5, 2022, 12:09 PM Larry Garfield w= rote: > > > >> Ilija Tovilo and I are happy to present the first new RFC for PHP 8.3: > >> Asymmetric Visibility. > >> > >> https://wiki.php.net/rfc/asymmetric-visibility > >> > >> Details are in the RFC, but it's largely a copy of Swift's support for= the > >> same. > >> > > > > I have two comments: > > > > - For reflection purposes, having two separate methods feels like it wi= ll > > be cumbersome; you'd need to check both to determine if you'd need to m= ake > > the reflection property accessible before changing the value. An > > isPublicSet() would alleviate that, or potentially a getSetFlags() meth= od > > against which you could apply a bit mask. You'd need to add a constant = for > > public set I both cases. > > Reflection is a mess, unfortunately. :-( > > There's already separate isPrivate(), isProtected(), and isPublic() metho= ds on ReflectionProperty, so this is consistent. Also, there's getModifier= s() which returns a bitmask; these new flags would be included there. All = these methods all do is check what is syntactically present, both the curre= nt ones and proposed ones. > > There's definitely room in the Reflection API for a "couldItBeModifiedFro= mScope($scope)" type method (and similar) that aggregates together symmetri= c visibility, readonly, asymmetric visibility, etc. into nice booleans. Ho= wever, that is notably more work than just adding more syntax flag methods.= It would probably be better as its own RFC, though I'd support that. > > If there's consensus that it has to be done here that could be done, but = we'd prefer not as it feels like scope creep. > > > - The number of items that appear to the left of a property is growing, > > making understanding a declaration increasingly difficult, and your > > discussion of future scope indicates that this is likely to get worse. = I'm > > wondering if this sort of behavior could be indicated via attributes > > instead? Something like `#[PropertySetBehavior(PROPERTY_SET_PRIVATE)]`. > > Attributes have the benefit of being separate from the property > > declaration, arguably more readable (one per line), and composable. Thi= s > > might play into some of the future scope items as well. > > The list indeed groweth, but there's a couple of reasons it wouldn't be a= ppropriate here to use an attribute. > > * It would mean get-visibility is a keyword and set-visibility is an attr= ibute. That's weird and inconsistent. > * There's a strong sense from many on the list that attributes should not= be used for language behavior. Ilija agrees with that position, and I don= 't care enough to fight it one way or the other. > * An attribute would be ignored in older PHP versions. For most attribut= es that's OK, but in this case it would be a potential bug source. Specifi= cally, it would mean `#[PrivateSet] \n public string $value` would be publi= cly settable on PHP 8.2, but not publicly settable in 8.3. That means the = integrity of the object is compromised on older versions. A keyword would = make that a syntax error, which in this case is preferable. > > > Overall, though, love the design simplicity! > > Yay! > > --Larry Garfield > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > Hello, First of all, this is exciting! Looking at the behavior for references, can we explore the edges a bit? (I didn't see any tests that cover this functionality in the PR) 1. Passing a function a reference to a private-set property is allowed, such as to sort(). 2. Returning a reference to a private-set property is allowed and usable. 3. Trying to get a NEW reference to a private-set property outside of the defined scope is not allowed. So if I'm understanding correctly, references to private-set properties can be used outside of the defined scope but they can't be created outside of the defined scope? If so, should we fire off a Notice when references are modified outside of the defined scope? I can see that being annoying in certain contexts, such as sorting an array, so maybe not? FWIW, this behavior doesn't apply to readonly properties because attempting to pass a reference to the property fails.