Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98964 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3661 invoked from network); 4 May 2017 12:51:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 May 2017 12:51:30 -0000 Authentication-Results: pb1.pair.com smtp.mail=tendoaki@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tendoaki@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.171 as permitted sender) X-PHP-List-Original-Sender: tendoaki@gmail.com X-Host-Fingerprint: 209.85.217.171 mail-ua0-f171.google.com Received: from [209.85.217.171] ([209.85.217.171:35542] helo=mail-ua0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CD/C5-02776-FC32B095 for ; Thu, 04 May 2017 08:51:28 -0400 Received: by mail-ua0-f171.google.com with SMTP id e55so7529441uaa.2 for ; Thu, 04 May 2017 05:51:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=z2DoYBNjI+StvmCS1mZh72mXJSWYmBy5Vmw05Knn8Kw=; b=KOaaVOwVUrvtMA9vGCRJh6YDxsXxvtwZdLSNEGvls0iifrnYbLo23o+zVil6Nhp0fg //+VkNUU0Yl98J4nVfrjywNcFT1JtEmS/8cmbrBhA0mzGKMqX0u36FoHTisP393Mm6Gn uGhvBP/p+OzEVZm75W7B1OBjMzUHfQhxWmwGM+Hnawlr3czXexfHGFwW2P3RWZnqWnmC K32+sX3I91bSffzlD//gFvxCFrk0p4UNQFeQHumFFIwIWjZuyVu5KysyCjWIo7XEwBEI iKbFGPJiAl6iNLkymsX+PRXDcHJafl3MUzpRyb8SVZkpp3p+HwReoyOKnbGYuwDP9ljR AIoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=z2DoYBNjI+StvmCS1mZh72mXJSWYmBy5Vmw05Knn8Kw=; b=uBPZlgXN8qzJ1WjGjsupDTSzqK+RvQtXZPb63v1iZuT6zYX3wIXNHHhF9B7A4+RfTh 7F0Xw7rw8yeHn3UXcv5W7EGEZDprHcGiFNqZh8vAJ7bwLcK7jJaFPPHRPy0u+8F7FjND BHvy9NzWMWjfbo4jAiesE52b/RikZp5aMW2bwVX8v0hckhGZnab5pyeTm07CKnRV9wHh 86j8MgXH0jmcPzmGP6SBlW/4K6NMQcvyCV8T3RITEy/r8MlvLr/VzHkcOlFosdp0Ky5B rGFwdeK4cwHvlCjlqQSCYkdOU3t4BKJ+FDMdKXxO5smiSlIe3z506F3zJGFK62RmGua+ B2wQ== X-Gm-Message-State: AN3rC/59KrMq1TOuvsXjLlfeLGigFdQaIf5Z5oimqT4Z4YM84lmtwKcj 1TGJcpvztqfcr95RTeGvD7rYjmkzr5yaeZw= X-Received: by 10.176.76.68 with SMTP id d4mr18801417uag.4.1493902284061; Thu, 04 May 2017 05:51:24 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.89.203 with HTTP; Thu, 4 May 2017 05:51:23 -0700 (PDT) In-Reply-To: References: <0b4f249f-f574-2dcc-4485-1d765bc4cb18@gmail.com> Date: Thu, 4 May 2017 08:51:23 -0400 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary=f40304361ce8f87f26054eb23a65 Subject: Re: [PHP-DEV] Add is_vectorlike($array) function From: tendoaki@gmail.com (Michael Morris) --f40304361ce8f87f26054eb23a65 Content-Type: text/plain; charset=UTF-8 For what it's worth, the Drupal assertion inspector calls these "Strict Arrays" since that's what they are - arrays in the true sense of the term found in all other languages. What PHP is calling an "array" is more accurately a "map" or "hash" There is value in this validation - https://www.drupal.org/SA-CORE-2014-005 relied on the attacker providing an sql injection where the code was expecting numeric keys. There's no easy solution - this is just one of those things where PHP is painted into a corner by backwards compatibility. Calling them vectors just seems weird though. Calling them strict arrays at a language level has its own problems. On Thu, May 4, 2017 at 7:23 AM, Jesse Schalken wrote: > 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/ > --f40304361ce8f87f26054eb23a65--