Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114691 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 39204 invoked from network); 2 Jun 2021 08:12:33 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Jun 2021 08:12:33 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C3FF01804BE for ; Wed, 2 Jun 2021 01:25:42 -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,NICE_REPLY_A,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-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 ; Wed, 2 Jun 2021 01:25:41 -0700 (PDT) Received: by mail-wr1-f46.google.com with SMTP id g17so1330227wrs.13 for ; Wed, 02 Jun 2021 01:25:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seld.be; s=google; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=1T5A/P2bHUUIaTqnMiELZBdR5tttUjH+K8m314acTco=; b=hLBb4pB4k6QPqsTh0PeyjyDsqZf+iZ8t4gUHJtwA5Av9avShgzK9plu2Yxl/1TdbMy ME1h+Jv7t7O/mOObZdqz9SFjeQUlIs8daLIYQcmQVz1wKliaw4xmZkvxPet1ItOaE13a /EzYTLmN/p0xyWXI3J7UretjrLpVWbPS+S0TlVSFkLqQopOEJTgOJzx0Qkbpnz1pXRN+ GEaFKck98zazitYVXjyrwXsUYGOlfbrk5Xlc8W/vFONtGvp9zr9Yq6RHwjVqRTAKEv5y uf2C0zivfXn5b6NIORh4sWthz38gP9vuUn9bVoH4oTHNEMzB0jseD4Dmw2ijDrCF6fRk 0uAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=1T5A/P2bHUUIaTqnMiELZBdR5tttUjH+K8m314acTco=; b=WXREtBIivZpEdfWGWlEp4jgsrTFe1REKoxwZ3zO21fYfLvCNecob5g25D7MygO/Ey+ UWKUXGtC4MhpSsAGwCIupPenXoq7nKCjlVzvlXeyyUCWwaQK4/bh7q+uDRdi4U2OMbey eq+dWZiK7QoaI9MI4J7NxvTPNhvdVsylKLDp+i+GJPnpBt+OYeStbTtWxQw3tUAwCjyx yBlwq5Mt3h69sy8M3UTwPK7xp6JBYMRlOjN+Ofvk/42lD0E9YS2LXIQow/zyquAsbGRq oAJycyCdVrosbAjvlipJ9AXJboxq2JX9oDkx2cZy35F7/OTcY1yduNCEHRsl40eQfPoK 12KQ== X-Gm-Message-State: AOAM531tvZXiBwhuwVPgM5Jtuo3PLxPx+K8c/tHQKjq0QlpyK38T7BsE 6cBlSosOMeEawEvaXCdt40ILPwHBrY4Gsw== X-Google-Smtp-Source: ABdhPJyMWLFnVibYv+/BGpsivCaYpjDXcsl1n0NyDycUKhbnXIkfs6AR3MDdzLOs4UteYoB39AJGRw== X-Received: by 2002:adf:f7d2:: with SMTP id a18mr17207640wrq.111.1622622340492; Wed, 02 Jun 2021 01:25:40 -0700 (PDT) Received: from ?IPv6:2a02:168:4b6e:0:8463:40f8:e947:1303? ([2a02:168:4b6e:0:8463:40f8:e947:1303]) by smtp.gmail.com with ESMTPSA id l5sm1841609wmi.46.2021.06.02.01.25.39 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Jun 2021 01:25:39 -0700 (PDT) To: internals@lists.php.net References: Message-ID: Date: Wed, 2 Jun 2021 10:25:36 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Subject: Re: [PHP-DEV] Regarding array_shift()/array_unshift() From: j.boggiano@seld.be (Jordi Boggiano) On 02/06/2021 00:34, Mike Schinkel wrote: > But from all this I do agree with you that just returning an array > would likely be acceptable. > ----- > > This would not be a great solution for really large arrays, but then we can't eliminate the need for a developer to have a reasonable level of knowledge, right? So: > > $unshifted = $array->unshift($new_element); > $shifted = $array->shift(); > > But, we could also possibly use better names for these: > > $right_shifted = $array->shift_right(...$new_element(s)); > $left_shifted = $array->shift_left([element_count]); 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? I mean sure one can call reset first to get it, but I find this isn't great ergonomics compared to the existing. Best, Jordi -- Jordi Boggiano @seldaek - https://seld.be