Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114701 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 7405 invoked from network); 2 Jun 2021 23:34:28 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Jun 2021 23:34:28 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 698551804BE for ; Wed, 2 Jun 2021 16:47:51 -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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 2 Jun 2021 16:47:50 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 23A78B47 for ; Wed, 2 Jun 2021 19:47:50 -0400 (EDT) Received: from imap43 ([10.202.2.93]) by compute1.internal (MEProxy); Wed, 02 Jun 2021 19:47:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=QF+bnE MJMp+viC2Yu6gUgfYRakZbVmlsbcEgv+Vk64I=; b=unw56xy/MR9RaxiXQjkESm ZF+wceHUAi2lbwi8rRaXKG6XWU8sKtPrBpMbTDqZ+MTKwZ00Bu/kwXTIs9SBfc4/ +dvOWD1aF3LmNkj3f8sbSOC+9uV/nT9fYWQdkikwy1DYFlsovMLpKu/RRV2NRf3O SEYbBxEZZ8FAayuOjhD/HG4DjrYfNZjudYWU6Rd+NlB6M+Ls80AYLo1vkl8oyTjm zLiDBBJ6as1c3Tn+Hxc7citA4xps9KkxaKgiAZCzsZCejPGTScI0TSRA6F7Tm+W5 BOPOhPaMmkTY5Cm5zm8okyKuUwBBxaDiehKkC2P1rON6quAQjexH+CY2aoqlDYdA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdelkedgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeeglefgkeduiedvvdetffeujefftdfhjeeiveehgfff keduveektddvledvvdfffeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 6417BAC005F; Wed, 2 Jun 2021 19:47:49 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-519-g27a961944e-fm-20210531.001-g27a96194 Mime-Version: 1.0 Message-ID: <075a0b81-32df-4496-b67d-2192a6e5a882@www.fastmail.com> In-Reply-To: <7722B520-327C-4F88-BD7D-208644D62A64@newclarity.net> References: <761D99C1-4728-4EE8-95F8-44A240AE1473@newclarity.net> <0857bb8b-456f-41d3-9a51-35f9ab629e61@www.fastmail.com> <7722B520-327C-4F88-BD7D-208644D62A64@newclarity.net> Date: Wed, 02 Jun 2021 18:47:29 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] Regarding array_shift()/array_unshift() From: larry@garfieldtech.com ("Larry Garfield") On Wed, Jun 2, 2021, at 6:15 PM, Mike Schinkel wrote: > > On Jun 2, 2021, at 7:07 PM, Larry Garfield wrote: > > > > On Wed, Jun 2, 2021, at 5:59 PM, Mike Schinkel wrote: > >>> On Jun 2, 2021, at 4:25 AM, Jordi Boggiano wrote: > > > >>> IMO for unshift() it'd be fine to return a new array, but when processing a list of things in a FIFO pattern I often used array_shift() to get the first "job" out of the array. If $array->shift() returns a new array then how do I access the first item? > >> > >> That is a really excellent point, something I did not think to consider > >> given how rarely I use array_shift(). > >> > >> But your comment causes me to ponder a number of follow up questions, > >> some of which are tangential. If any reader feels these tangents are > >> worth discussing please make another email and quote my relevant > >> comments so we can have a dedicated thread for each. > >> > >> 1.) Given Nikita's position that it would only be viable to offer a > >> syntax that simulates method calling for arrays if the methods > >> themselves are immutable can you envision a solution for allowing > >> $array->shift() functionality that would address getting both element > >> and shifted array without resorting to by-reference parameters? > > > > $list->head() (returns first item) > > $list->tail() (returns all items but the first one) > > I assume $list->tail() would still have the O() problem in PHP, though? > > -Mike If implemented like an array, yes. If implemented in a more efficient way in C, potentially not. Or at least a smaller constant multiplier with n. (If something is O(n) but the cost per in is very small, then it being O(n) is not a big deal. If the cost per n is huge, it's a very huge deal.) --Larry Garfield