Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122668 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 4D2861AD8F6 for ; Sun, 17 Mar 2024 16:46:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1710694014; bh=CtbwtZa3MyHJhvZ1CSMhggRggPeok7wFwI/EME//a+Q=; h=Date:Subject:To:References:From:In-Reply-To:From; b=e5H20cXpS6zZBiSpqorW07W71TXVrByb2hJGaqYJPj4nAWMi9+kSHI9z8OZ1KYhfj kVNLzUtdI1KG3Lz4PHIzTMA8nIeywYQIkym7TKSrUYn3Gj9BFqlh5tKwmx1wbyjxqd titgBKdv2QNrKYvT3f64qTEb15/GF43/Vy6m28xVc/Vgs97l25nak+ZJ0Ft9pogzFW ulaAvSVIWM3ooq7ZPKaO3n16/6y2ZJ8iFVznFXOEBH19QTD0NTzcFKsD6LBGIf4RkC 5XNYIgCCwhuTFm4DCzZzEx7n7BWM6fakGdmhvOdQedqldUDY00N6QgJTs1QWwDcPk9 DMbeDvLzqlYLg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EAC7C180076 for ; Sun, 17 Mar 2024 16:46:52 +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, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from wfout6-smtp.messagingengine.com (wfout6-smtp.messagingengine.com [64.147.123.149]) (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 ; Sun, 17 Mar 2024 16:46:52 +0000 (UTC) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.west.internal (Postfix) with ESMTP id DE4421C0008D for ; Sun, 17 Mar 2024 12:46:30 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Sun, 17 Mar 2024 12:46:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :content-transfer-encoding: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=1710693990; x=1710780390; bh=ysx7+zY4ybQ3X+WFNtlh2S8Oi+cjQwwcdEa8ssvntR8=; b= kv3wd44xk505RfayiGIQEyy/+YCVADNv3lJQpIbm0P67veBnHeIolihrwFi/hXnd qBGZbRkzl4+u8x61AY+4Ify2VpookhXvpkkXo8Fap87BXG1auaxlpCxFP1ApVPNW IN/q6kfpE51CKrCYuFNGZvsVxEh2zVvh3G1CN/AUT3eQ1v4wDybV0gkFEpUWC84L deKh7v6JyCGC3faSPO/khr0n5pYCRPhX5qvYM8nGXqr/xuc7azFhs8T/OgpcsyI9 Mhi1oqvsEC3Rtir+MjJmFXuiLaJDjzF0GMTS3JmST+Q000zn5yXXbI42GTecSxkR nF2cP0hTJ4Svc/NEwmb+Wg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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=1710693990; x= 1710780390; bh=ysx7+zY4ybQ3X+WFNtlh2S8Oi+cjQwwcdEa8ssvntR8=; b=h owzuX1h3NFHs9HgrYGLxhqc0e83IQh6EP2SNPniDulEKDyrPTLnhUrYVR4danpSh qJf7ZsW+dd6qMYdiY+4pCHcybZZKpoZZzwiAPKm6m9LDeyuRzAQc6m1QM+QLdpzt 54B+rT3NzADXRp6ral+wn4sI1L3VUJ3e7N+FflKjqzF25g0HenJUBttcgRD+l9Kj rxVs3/yYzs/Hs7lqG/Tob1/lpirgu2o1lr/WyXlXgwP9sEcSAw+Lg8tqLRQ57k0a vsSS98FTeHvizSX44nfz1jvm4dnoLKyw4THhPiJ7HXdbFdmk+0cbLZYujCC33Kqq SazuSJk/U1F+UzwphI3og== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrkeehgdeilecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefkffggfgfuvfhfhfgjtgfgsehtkeertddtvdejnecuhfhrohhmpedftfhofigr nhcuvfhomhhmihhnshculgfkoffuohfrngdfuceoihhmshhophdrphhhphesrhifvggtrd gtohdruhhkqeenucggtffrrghtthgvrhhnpeeuleevffduhfekudfftdehgfetfeetkeeu gfduheeuteffvdevfeffkeeulefgvdenucffohhmrghinhepghhithhhuhgsrdgtohhmpd gtohhnthgrihhnvghrqdhofhhfshgvthdqsggvhhgrvhhiohhurhdrmhgupdhphihthhho nhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehimhhsohhprdhphhhpsehrfigvtgdrtghordhukh X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Sun, 17 Mar 2024 12:46:29 -0400 (EDT) Message-ID: Date: Sun, 17 Mar 2024 16:46:23 +0000 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [Pre-RFC] Improve language coherence for the behaviour of offsets and containers Content-Language: en-GB To: PHP internals References: <1MzJ8G_MuG-LJsMSoGDIRBmSODjO4hxPACqMoQYfx83MS-du6sskpNLJ45HnzPYMoUNkXyGiZEUAtFk-uyeGDv_Kwg6Qgtod05pXCQH-8M8=@gpb.moe> In-Reply-To: <1MzJ8G_MuG-LJsMSoGDIRBmSODjO4hxPACqMoQYfx83MS-du6sskpNLJ45HnzPYMoUNkXyGiZEUAtFk-uyeGDv_Kwg6Qgtod05pXCQH-8M8=@gpb.moe> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 11/03/2024 12:52, Gina P. Banyard wrote: > I would like to get some initial feedback on an RFC I've been working on for the last 5–6 months. > The RFC attempts to explain, and most importantly, improve the semantics around $container[$offset] as PHP is currently widely inconsistent. > > [...] > > RFC: https://github.com/Girgias/php-rfcs/blob/master/container-offset-behaviour.md Hi Gina, I've just read through this thoroughly, and am simultaneously impressed with your investigation, and amazed at how many inconsistencies you found. I think the proposed granular interfaces absolutely make sense, given the different uses people have for such offsets. My only hesitation is that if you want "everything", things become quite verbose: class Foo implements DimensionFetchable, DimensionWritable, FetchAppendable, DimensionUnsettable { ... } function bar(DimensionFetchable&DimensionWritable&FetchAppendable&DimensionUnsettable $container) { ... } Unfortunately, I can't think of an easy solution to this without some form of type aliases. As an experiment, I tried writing a variation of Python's "defaultdict" [1] using all the new hooks (without actually testing it against any implementation). Here's what I came up with: https://gist.github.com/IMSoP/fbd60c5379ccefcab6c5af25eacc259b Most of it is straight-forward, but a couple of things stood out: * Separating offsetFetch from offsetGet is really useful, because we can avoid "auto-vivifying" a key that's only been read, never updated. In other words, isset($foo['a']) can remain false after running var_dump($foo['a']), but $foo['a']++ should still work. * The fetchAppend hook is quite confusing to implement, because it's used in a few subtly different scenarios. For instance, if it's actually $container[][$offset] = $value there is an implicit requirement that fetchAppend should return array|DimensionWritable, but presumably that has to be enforced after fetchAppend has returned. I'm not sure if there's anything that can be improved here; it probably just needs some examples in the user manual. [1] https://docs.python.org/3/library/collections.html#collections.defaultdict Over all, I think this is a really great proposal, and hope it proceeds smoothly. Regards, -- Rowan Tommins [IMSoP]