Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98980 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59518 invoked from network); 6 May 2017 17:48:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 May 2017 17:48:00 -0000 Authentication-Results: pb1.pair.com smtp.mail=derokorian@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=derokorian@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.44 as permitted sender) X-PHP-List-Original-Sender: derokorian@gmail.com X-Host-Fingerprint: 209.85.218.44 mail-oi0-f44.google.com Received: from [209.85.218.44] ([209.85.218.44:35323] helo=mail-oi0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 98/8E-02776-D4C0E095 for ; Sat, 06 May 2017 13:47:58 -0400 Received: by mail-oi0-f44.google.com with SMTP id l18so16269178oig.2 for ; Sat, 06 May 2017 10:47:57 -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 :cc; bh=9NoQqbD7J2kvf+ggEmiO5a+x+lGkH0zVvAXpVMUfp+Q=; b=RelyKI4sp/BFD8nGoUcsAg3SkZmWYgKvagoElEqqn2iuQcJsuWRmV5a4vZKjriHaTG eM5W+ezfAEfIyu2V8n0s4roLw/2BrfGvMKzI0Aj9IsUaN8R2QUOt+NXVib/hfql++/cE 2O7IsR2HMaEmbe8fI3maBdtXjpwBuNmyfixo99YAdO/22EbZtydRARaeAmV48ghEwLMM EnfztUVy7jABXJSXChMEi7osXiCsOY1RsUVETs4XQUWPU9Zf2hlxSxy/o/7YdLedDaeY qbqVpgFIllpoL3fKUB1RsZyE9IY4TlF+7NE0KG8wAldYyygTS5Jt5Dilm+B3wKondt46 USxQ== 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:cc; bh=9NoQqbD7J2kvf+ggEmiO5a+x+lGkH0zVvAXpVMUfp+Q=; b=UJHXSppbIe/WIE4F2KwBRRERp310rw86scyjqNoFyFbY/mohFcuGHwgMR6DK8FmBgv Vz2TaPr2PDvn40JPV2D79JOjBlQ579Cy1e0pHXptWw9FDzyPY0rWA9KwTFAO+du20OrM saodapJhOuZfiDFwd4H1x9hch2FX2S3RM/79NCrUemhGky7wBVoAlv+2pM4oNYJl1iY9 Feu29509/hbKe9kIUbSMD2yZYvKI+oaTt2URzDEzKtIR3HKHeawbt57ibqLFwhE6b05M ziX21cy7tqVhNsvBQA6po4F3t70rjjDxT3nAITe4upf4UyLd9F6dk2SsKRNSXQ69tgaq BdGQ== X-Gm-Message-State: AN3rC/647c2/zirpebrwI0TCocU+6SAK0POU9nwggWVIzPVpVxl6/gWH 96E+2PnXsePeZ4shZfM5c/U+8C9aCw== X-Received: by 10.202.117.67 with SMTP id q64mr9836235oic.18.1494092875323; Sat, 06 May 2017 10:47:55 -0700 (PDT) MIME-Version: 1.0 Received: by 10.157.40.87 with HTTP; Sat, 6 May 2017 10:47:54 -0700 (PDT) In-Reply-To: <8FCFC367-D5B9-4259-BCAF-05C061F23F52@gmail.com> References: <8FCFC367-D5B9-4259-BCAF-05C061F23F52@gmail.com> Date: Sat, 6 May 2017 11:47:54 -0600 Message-ID: To: Rowan Collins Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a11c16720186004054ede9b54 Subject: Re: [PHP-DEV] Add is_vectorlike($array) function From: derokorian@gmail.com (Ryan Pallas) --001a11c16720186004054ede9b54 Content-Type: text/plain; charset=UTF-8 On Sat, May 6, 2017 at 9:42 AM, Rowan Collins wrote: > On 5 May 2017 22:19:51 BST, Ryan Pallas wrote: > >I just read this thread and am wondering what exactly is the use case? > >Like > >are you going to do something if it is vector-like, and do something > >different (or not do anything at all) if it's not vector-like? I mean, > >if > >you have to crawl it, and need a vector, why not just call array_values > >and > >guarantee you have a vector? > > I gave one use case in an earlier message: many serialisation formats have > a different form for ordered lists vs key-value pairs. As an obvious > example, look at JSON arrays and objects, and many other formats have > similar types. > Ah, so you would do something like private serializeArray(array $data) { return is_vector($data) ? $this->serializeVector($data) : $this->serializeAssoc($data); } is that right? > It can also be quite intuitive to have a function accept either a list of > prepared items or a set of key-value pairs representing structured data. > For instance, HTTP headers might be prepared like ['User-Agent: example'] > or structured like ['User-Agent' => 'example']. Turning the second into the > first requires more than just running array_values, but can be skipped if > the input is known to be vector-like. > Ah, that's a great example and makes perfect sense now! Thanks :) > > Arrays that have integer keys, but not all sequential, can be a bit of an > edge case, but treating them as a list throws away information, so it's > usually safer to treat them as key-value pairs. > > Regards, > > -- > Rowan Collins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --001a11c16720186004054ede9b54--