Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124443 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 A9D981A00B7 for ; Tue, 16 Jul 2024 02:27:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1721096941; bh=EW3hIjR6xwfhyV/3Be+QdhCvgbPHm2KY4T1TR82FdrM=; h=Date:To:From:Subject:In-Reply-To:References:From; b=hdO8gOjqnTTIWF6c6CYTs2rgSlHRij+yYWPU5fUrO6yPP5w0L4U+6GqFfK/NiPcuD 9gCw2M5clG8rHf87ICkC/sN6kze8DjQjUJQATYjf5vY2XHrXSzHwbvMB1CN4EPJiAi Q1R36AKbJ+kN7SrWv5syfeM+qsyjLfDLfjbSgBflzAow7GHxg8DTZnRzvB5xYzscV0 Uzu8ve4yOOpDC5hbkJ0fKzKvySul2wDpaih8unjZ1KJ5Nl/cdj7L5//DPIQqkNwwLd QAzQva44sdRvkFQts1anwi93cGDeurUrgndwu9fiDsKCf8Tqiv2uusvF4j7wF+wabU VobVFtNMgR7oA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E5550180051 for ; Tue, 16 Jul 2024 02:28:59 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-4317.proton.ch (mail-4317.proton.ch [185.70.43.17]) (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 ; Tue, 16 Jul 2024 02:28:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gpb.moe; s=protonmail2; t=1721096847; x=1721356047; bh=EW3hIjR6xwfhyV/3Be+QdhCvgbPHm2KY4T1TR82FdrM=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=t0mqhqw+AKzcs16QjWkeSRUs3AX+JmA0vS/797eQ2TeUCkta05hNqM/DBCrjFpSmF clR1riSk0AEOUihxCPh3W6XosMmVFbpLRP3P6ZS6oAvmLdpF/biaSUXAmkFqjqq2pz vaq8h8MfEZTcOGy0zf3qPiMnT1BEeXfdxEA77Xvs/kzGgV3DoJjub5e0mrotnUYeAq Qo6XPhpdCwFccxiyRP5Qp5Mazg2zHuwe6iaYN+5lav6Ag7EhayWN1b2LelT2xFV0Qq adTMcI4EuJXJi0JFus1dqff1Gm3MKQ4lXZCAGY/OR55j+r4I1SYbIDmAMX3P85vWd0 8+OrJwn+Jhj0w== Date: Tue, 16 Jul 2024 02:27:25 +0000 To: PHP internals Subject: Re: [PHP-DEV] [RFC] Improve language coherence for the behaviour of offsets and containers Message-ID: In-Reply-To: References: Feedback-ID: 96993444:user:proton X-Pm-Message-ID: 1775a445c3beef87b0d2845e7202ec4a511c7f1c Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: internals@gpb.moe ("Gina P. Banyard") On Thursday, 4 July 2024 at 14:52, Gina P. Banyard wrot= e: > Hello internals, >=20 > I would like to formally open the discussion on an RFC I've been working = on for the past year: > https://wiki.php.net/rfc/container-offset-behaviour >=20 Hello internals, Ilija did a review of the RFC and pointed out some good questions and remar= ks. I've clarified, and amended the implementation, that ArrayAccess extends Di= mensionReadable, DimensioWriteable, and DimensionUnsettable. I've added to the RFC the deprecation of using integer offsets when using A= rrayObject with a backing object, as it turns out supporting this adds a lo= t of complexity in the engine that would be great to remove. One of the new warnings the RFC introduces is when using a bogus value as a= container in isset()/empty() other than `null` which shortcuts. This shouldn't cause many issues, except possibly if the container is `fals= e`, as it may be the result from an internals function call which returns f= alse on failure instead of null. The question is if `false` should have the same exemption as `null`? The behaviour around the increment and decrement operators is slightly unfo= rtunate. Incrementing an array offset or object property is treated more like a read= -write operation, however, due to the lack of VM opcodes, it is treated lik= e a fetch for object offsets. After discussion with Ilija it seems wise to make this an Error for now so = that we can support it properly in the future, and have the increment obser= vable via the offsetSet() method. There are still a couple of questions around the behaviour of ArrayObject w= ith property hooks that I need to look into, especially around the current = ArrayObject behaviour with ignoring the __set() and __get() magic methods. The final question, which is somewhat tricky, is how to deal with auto-vivi= fication? The gist can be explained with the following code: $obj =3D new Vector(); $ref =3D &$obj[0]; var_dump($ref); $obj[1][] =3D 'append'; $obj[2][50] =3D 'set-to-offset'; For arrays, $ref would be NULL And when nesting them, the "null" auto-magically becomes an array. However, for objects it is not clear what to do, if the fetch() method crea= tes an object, then the initial $ref would already have a auto-vivified container. However, if NULL is returned, then the nested append and offset write would= not auto-vivify a nested Vec container, but a standard PHP array. I currently have a crude prototype where, in the nested dimension case, I i= nstantiate a new object of the same type, but this doesn't call the constructor (which I could do), but passing argum= ents to it is impossible. Another solution is to add another interface, e.g. Autovivificapable, which= would define an autovivify() method which would be called in those instanc= es. Does anyone have any opinions about this? I have also slightly amended the RFC and added a BC break recap section. Reminder, the RFC on the Wiki is located here: https://wiki.php.net/rfc/container-offset-behaviour And on GitHub here: https://github.com/Girgias/php-rfcs/blob/master/container-offset-behaviour.= md Best regards, Gina P. Banyard