Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122682 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id E7BDC1AD8F6 for ; Mon, 18 Mar 2024 14:04:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1710770683; bh=HLB9BGZJqBhCONFhTDHdqCEnif0I86MrCJvaI7i0gY8=; h=In-Reply-To:References:Date:From:To:Subject:From; b=Lg+TC8nu84OowPg4ClPuWtilYcZ3lN1RMmFB9EL8apvs3NXaRNOYQpdcxMhbaWnG/ vHSnZcYEvlsyEKn/+umIuFeTRXRkcedQciDYLyQEdOFp6xBEmoYZyY+Jkpxk2AM+bY J60AwkO/U0rCUruvpR9Nr96ugcJas0r47Dc5LNodDoAAtFGyD+49Xi0xVBLQaz3cNz mKIlJ/g3qt7qqRVrEUHEEgAhCEW557bXRu5061FU1mZGFPaz/3MAozDInLAyOm6qqa AkmeVw5tS28cXiwys8wt9X6a9yzQEu80k6FZjexXbfmauIEPQp8xfGpsFhWttdiWWg N3eBIfBDRD/8g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 337BF180081 for ; Mon, 18 Mar 2024 14:04:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 18 Mar 2024 14:04:41 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 85DAF5C006D for ; Mon, 18 Mar 2024 10:04:21 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Mon, 18 Mar 2024 10:04:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-type:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1710770661; x= 1710857061; bh=NPwh+QpU/3rsmFPHdK7gMdxX9pqSSU6bD0ecb3ViFtQ=; b=L He9HjJnDWuSa9RY4mW6VZ6+rAcs25c0Fet7jVOMtFfzh7nzPTK0v6a536i95mWBx 1sX+CEQNreSjxLvEqPTQA7q1RS3OiyrRSOwrS+Z6bSVBmCmqCqUXSjsNz4HMxCz5 34YTBcNS18Lo96jBT5IaXVTmEGOqJSm8tSz5CTp4MBNsUic1w1DH3DRUDSlfmnY+ 2NUAoELoUIzsCjs0UFVRvgiviNHkdnnOTz+KAneNnRS/bhLWVFr7PoIIgGSr36wP RlXJSgfhewvbmg27v6r4A+jf8dGk9NDCnRc18Hah3hmMnITqbildNUDQ+Iu8ds42 iT8jO7P1X+1NMOBUDKjkw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1710770661; x=1710857061; bh=NPwh+QpU/3rsmFPHdK7gMdxX9pqS SU6bD0ecb3ViFtQ=; b=R6v9se43fhCBFEK9H8CiMUUObnLUowC7tJcwiNb2Q5Lj uQimj0oYLuRuiPqVYORFSorOenZZd1JJCL/SgymM/p3EINY6i/QV8QqpT96Cwak6 C1le2B35Z+zosK4rPzab3OXW6XP35oCHfuyQuYJglKSKUnoVh2q/5NB7PCNFGhBE lEiinUHWIFaa2RfO107IsmKYDJbEAAkiwY6M9Ftj7GmHm3I2cgHZ9xIaaML4Vj7h o62k/ClscEyBqJ4QkTmKUJP6pbfiDzKpOiAZfFCsb/0TxkRE9BZ+YBVgF2pJ/IxK N+1aGpqzc9A+ac/JIEEJZZHVxvnbnUC8eQ1z8gfALQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrkeejgdehlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgrrhhr hicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh eqnecuggftrfgrthhtvghrnhepffegveefkefftdeutdekvedtteevieetkefhffdtgfei iedtueetjedvkeekffeknecuffhomhgrihhnpehgihhthhhusgdrtghomhdptghonhhtrg hinhgvrhdqohhffhhsvghtqdgsvghhrghvihhouhhrrdhmugenucevlhhushhtvghrufhi iigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlug htvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 37ED71700096; Mon, 18 Mar 2024 10:04:20 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-300-gdee1775a43-fm-20240315.001-gdee1775a Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: In-Reply-To: References: Date: Mon, 18 Mar 2024 14:03:37 +0000 To: "php internals" Subject: Re: [PHP-DEV] [RFC[ Property accessor hooks, take 2 Content-Type: text/plain From: larry@garfieldtech.com ("Larry Garfield") On Mon, Mar 18, 2024, at 9:13 AM, Lynn wrote: > In regards to arrays, what about additional operations next to get/set? > I doubt this solution will cover all the use-cases or perhaps even > over-complicate things, just throwing the idea out there. > > ```php > class Test { > private array $_myData = []; > public array $myData { > get => $this->_myData; > append => $this->_myData[] = $value; > } > } > ``` > > Thinking about the other post about offset and containers > (https://github.com/Girgias/php-rfcs/blob/master/container-offset-behaviour.md): > ```php > class Test { > private array $_myData = []; > public array $myData { > get => $this->_myData; > append => $this->_myData[] = $value; > write_dimension => $this->_myData[$offset] = $value; > } > } > ``` Those hooks may be possible; we'd have to try it and see. However, they also wouldn't be able to fully emulate arrays. $foo->bar['baz'][] = 'beep' could get very weird. Those wouldn't cover unsetting. Array functions like array_splice() still wouldn't work. Basically, there will never be a way to make arrays 100% transparent with hooks. That's why the RFC recommends still using a method for array modification, as that's already a very well-understood and flexible approach. Fortunately, as currently written (append and write_dimension are forbidden), those additional hooks could be considered and added in their own RFC in the future with no BC break. Whether or not they make sense or cover "enough" use cases is a question that could be answered in the future, after Gina's RFC passes. So on this one, I think "punt" is the best option for now. It can be safely revisited in the future. > Is this issue restricted to arrays only? From my understanding objects > functioning as arrays are already by reference and thus should not > suffer from this? > ```php > class Test { > private ArrayObject $_myData; > public ArrayObject $myData { > get => $this->_myData; > } > > public function __construct() { > $this->_myData = new ArrayObject(); > } > } > > // would this work without issues? > $obj = new Test(); > $obj->myData[] = 'test'; > ``` Mostly correct. Objects pass by handle, not by reference. (You can pass an object by reference instead, and it behaves subtly differently.) But the net effect is the same. Your sample code there would run fine. --Larry Garfield