Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114274 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 94676 invoked from network); 4 May 2021 16:26:42 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 May 2021 16:26:42 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 139031804BD for ; Tue, 4 May 2021 09:32:46 -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-io1-f51.google.com (mail-io1-f51.google.com [209.85.166.51]) (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 ; Tue, 4 May 2021 09:32:45 -0700 (PDT) Received: by mail-io1-f51.google.com with SMTP id b10so7669513iot.4 for ; Tue, 04 May 2021 09:32:45 -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=TqsGuS2laHDKvmuhjvltpIygs1W84J0EHv8IemfooBM=; b=fcV4bm5WgY3uqNz1cMfMaMO+h9L2P0vDKPnOQgIhfUWuh0wcECDOnk0m8+XwoP7uG5 9kWkZgZyrpQQXRfvHavkCk+5UNZAehTbmFqlt9C+xm+/oCZ7tVEYOEGUV+YiQd0rO4Dl b5+n8DmXdIw6rWYcQzFvphf9Q3WfePB418GmtbUEAlDj4P66nlKtCTKKZfpdqv9ZxdD1 eo/9F/9dRoRepHdnQXKIkQZtg7QGMwUWKxhIEhXH1U4ZPiwGamQ13OmB1ChGUbWha9bF hn6jkLTN5Cyxqt6zJ2jEY7nU8N93f5OgzweB0/Dd3kITNN+7SdWsXC0FXNdG7hyFy6ZP BJsA== 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=TqsGuS2laHDKvmuhjvltpIygs1W84J0EHv8IemfooBM=; b=ufrcbgHF2JDKw1uM730LKY5dxR2InSHm68MewHZwogQRWTHfS6MCHj8Sx/P05cJc++ ElIl+bzupvgy/VkAw4eS6KmgLth/8HsNkWOSjqyQpEDcDDkQo3T3hSeXS8WHU+rCIDjE YssNLY/fH22HwPVvH5MY7Rc4D3eypcOsDCpRVsJvbbvM65dOZGt9kpXueDPjjfTZbRUz WbP9pNDX/kzvXhjV1AV1xvhWidZ9uZHc5c4bz9/s2dIoHDUxAiw8mwhaGvh6cWggYLlZ DilfPQ9GBjGspdoBVyRY7tHnILYiiw8KlxZrEKDUErhJRsGtm30VmkvIIH0jivE87sW+ 9Hlw== X-Gm-Message-State: AOAM533unLktW4dPm5xb/+DrS6R+CzqbWzzPRv2IH6TJt4YcKEW1lCqS PsXRfaNoPPgDid4dRvZa6+pBV2ZEEjnmcdg5GUk= X-Google-Smtp-Source: ABdhPJwtRl5NAjELyYA7GuMEXhaGRbBGESnP8V7jMOjvkhR7PJmx+ggCtlF37Pqp+gCWoPRWAIkmGu6PYZ6Ca3B2Z+Q= X-Received: by 2002:a05:6638:4a:: with SMTP id a10mr24768021jap.142.1620145963981; Tue, 04 May 2021 09:32:43 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 4 May 2021 18:32:31 +0200 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000aadceb05c183a003" Subject: Re: [PHP-DEV] [RFC] Property accessors From: ocramius@gmail.com (Marco Pivetta) --000000000000aadceb05c183a003 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hey NikiC, On Tue, May 4, 2021 at 4:21 PM Nikita Popov wrote: > On Tue, May 4, 2021 at 12:58 PM Marco Pivetta wrote: > >> Hey NikiC, >> >> On Tue, May 4, 2021, 12:34 Nikita Popov wrote: >> >>> Hi internals, >>> >>> I'd like to present an RFC for property accessors: >>> https://wiki.php.net/rfc/property_accessors >>> >>> Property accessors are like __get() and __set(), but for a single >>> property. >>> They also support read-only properties and properties with asymmetric >>> visibility (public read, private write) as a side-effect. >>> >>> The proposal is modeled after C#-style accessors (also used by Swift), >>> and >>> syntactically similar to the previous >>> https://wiki.php.net/rfc/propertygetsetsyntax-v1.2 proposal. >>> >>> While I put a lot of effort into both the proposal and the >>> implementation, >>> I've grown increasingly uncertain that this is the right direction for = us >>> to take. The proposal turned out to be significantly more complex than = I >>> originally anticipated (despite reducing the scope to only "get" and >>> "set" >>> accessors), and I'm sure there are some interactions I still haven't >>> accounted for. I'm not convinced the value justifies the complexity. >>> >>> So, while I'm putting this up for discussion, it may be that I will not >>> pursue landing it. I think a lot of the practical value of this accesso= rs >>> proposal would be captured by support for read-only (and/or >>> private-write) >>> properties. This has been discussed (and declined) in the past, but >>> probably should be revisited. >>> >> >> I've skimmed the RFC: it will take a lot of testing to see how much this >> impacts BC, but potentially a lot. >> >> A few things that came up so far: >> >> * instead of allowing by-ref `get` declaration, can we just kill it >> here, before it breeds again? I don't think I need to explain the woes o= f >> by-ref to internals, but removing the ability to declare new accessors >> by-ref would be a huge win for the engine and the language long-term. >> > > The primary functionality by-ref get is needed for are operations on > arrays, such as $foo->bar[] =3D $val. This probably isn't particularly > important for explicit accessors, but may be a non-trivial limitation for > implicit ones. For example, you wouldn't be able to have a "public get, > private set" on an array property, for all practical purposes. Of course, > we could allow that to work fine for implicit accessors, without any > by-value vs by-reference get distinction. Would probably open up question= s > regarding compatibility during inheritance though. > > Of course, I am generally sympathetic towards killing references with fir= e > :) > I'd strongly advise killing by-ref array push there: it's an acceptable limitation, for the amount of benefit we get :P In fact, people doing `__get` now are already familiar with "Indirect modification of overloaded property" (https://3v4l.org/6dTXK) As for use-cases around using by-ref, it is true that some of my libraries use by-ref to shadow/override object properties, but I'd rather kill the library than have by-ref proliferation. > * what does an array cast of an object with accessors look like? I assum= e >> only properties backed by storage will appear? (Yes, the array cast is >> still the simplest/most useful pure API to inspect object state =F0=9F= =98=81) >> > > That's correct. This is mentioned in > https://wiki.php.net/rfc/property_accessors#var_dump_array_cast_foreach_e= tc > (I've renamed the section to make it clearer.) > Thanks! Perhaps I missed it :-) > * what is the design decisions around same-visibility declarations >> causing compile errors in inheritance scenarios? Those would make BC >> unnecessarily complex, if a parent type declares a new accessor with the >> same name: variance is understandable, but same visibility errors seem a >> bit too much >> > > I'm not sure which error you're referring to here. Could you share an > example (or point me to the example in the RFC)? > From this example: class Test { // Illegal: "public get" has higher visibility than "private $prop". private string $prop { public get; set; } // Illegal: "public get" has same visibility as "public $prop". // This visibility modifier is redundant and must be omitted. public string $prop { public get; private set; }} I'd perhaps mis-interpreted the error? Why is `public get` illegal? Also, is the example missing inheritance? Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ --000000000000aadceb05c183a003--