Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98963 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98491 invoked from network); 4 May 2017 11:23:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 May 2017 11:23:10 -0000 Authentication-Results: pb1.pair.com header.from=jesseschalken@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=jesseschalken@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.174 as permitted sender) X-PHP-List-Original-Sender: jesseschalken@gmail.com X-Host-Fingerprint: 209.85.223.174 mail-io0-f174.google.com Received: from [209.85.223.174] ([209.85.223.174:32825] helo=mail-io0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 49/65-02776-C1F0B095 for ; Thu, 04 May 2017 07:23:08 -0400 Received: by mail-io0-f174.google.com with SMTP id p24so18501507ioi.0 for ; Thu, 04 May 2017 04:23:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=c7VS7QhiMHWhjOsnbrYKJumhcExgP3uxH/mvJd4XjJY=; b=mHJHgw+eUlyG7z0pWML65Nq0txpxjKI/RRmXq9erALnG/hUv4eqCwaW9pSCNV6jTFU SIRbwK5n767iGc2WipPh7dWbayPhZprZtzlz11exNHm710O/dU/zttCKDb8RIs5gQOSP T7VBxmgbCL9MrEr/kwHaN3h2J1rMdiL7+ZBzcsGRk66onmUZNU2LIXC7VB5jJ6zF6EG0 fnleUKt3Agyf39x+AUzEIVBLr2RrxOKe05XMCPND3q1Q1BvUGcFyB0cDc+m/0LfjzN1R L0nELC5EnT1u2aSru0/8LEz/w5Rt03/oiManLrs9THBDAA/35EnHsCTx95a+qtlEJgBV Ugxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=c7VS7QhiMHWhjOsnbrYKJumhcExgP3uxH/mvJd4XjJY=; b=WhmgjJP4B3nxA0A47LNVqxhNGlXjNwRYtD5id/p4gWoc81bzunjBiRFRETggERi1/3 Q+74rUCsWsCSpC1XlDfRvfyLV19odSFOhWN89ltFGynJEhTmroJYsLAPF8JPtghwGSBe p1+eB51QvkmZ2t26tbpAyWDGlv6tlZs0/tfHjaYvc7DSijbPFKQnsJtKYD406Pqo9kU4 +cFjvp9mhqPBhoM4FHdIkolTWE7c4LfxTE1Pi/yaNQ3CP3j87IE3nUQnz8oyCDqn9ixA xvU9CVIEfjXx482TBXUVk36XK+LXklty6gWqS2dubKddKcOQqj+I5rlOgDq3xqIhJx13 HNjA== X-Gm-Message-State: AN3rC/7F/zbMGvmfDhQBsgdAOxg8IwwE8mVrUk3OkwcjVPkhfMp+EA2y 1+xW0e8WQLV5FDLcOgPWcdGLSEiB5w== X-Received: by 10.157.68.150 with SMTP id v22mr13988698ote.250.1493896985919; Thu, 04 May 2017 04:23:05 -0700 (PDT) MIME-Version: 1.0 Sender: jesseschalken@gmail.com Received: by 10.74.134.135 with HTTP; Thu, 4 May 2017 04:23:05 -0700 (PDT) In-Reply-To: <0b4f249f-f574-2dcc-4485-1d765bc4cb18@gmail.com> References: <0b4f249f-f574-2dcc-4485-1d765bc4cb18@gmail.com> Date: Thu, 4 May 2017 21:23:05 +1000 X-Google-Sender-Auth: qDNazXKw5v_l_4d7fpMjBaCCE6A Message-ID: To: Rowan Collins Cc: PHP internals Content-Type: multipart/alternative; boundary=f4030435397c2d4521054eb0ff87 Subject: Re: [PHP-DEV] Add is_vectorlike($array) function From: me@jesseschalken.com (Jesse Schalken) --f4030435397c2d4521054eb0ff87 Content-Type: text/plain; charset=UTF-8 On Tue, May 2, 2017 at 7:55 PM, Rowan Collins wrote: > +1, I've been thinking of making a similar suggestion. We can bikeshed the > name (it should certainly start with "array_"), but I think there's a very > good case for having an optimised implementation built in, given the > opportunities for short-cutting based on representation details. > Something like array_is_vectorlike(), array_is_vector() or array_is_sequential() sound good to me. You could also do the opposite, array_is_assoc(). As an example use case, serialization formats often dynamically switch > between an "array"/"vector"/"list", and a "hash"/"dictionary"/"table". I > came upon this example recently: https://github.com/php-amqplib > /php-amqplib/blob/master/PhpAmqpLib/Wire/AMQPAbstractCollection.php#L218 Another reason this function would be of utility is that it would discourage even more inefficient implementations that allocate new arrays, like the one in that code ("array_keys($val) === range(0, count($val) - 1)"), and nearly every single answer to this StackOverflow question (except mine): https://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential/ --f4030435397c2d4521054eb0ff87--