Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91165 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 93903 invoked from network); 9 Feb 2016 15:41:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Feb 2016 15:41:49 -0000 Authentication-Results: pb1.pair.com header.from=guilhermeblanco@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=guilhermeblanco@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.179 as permitted sender) X-PHP-List-Original-Sender: guilhermeblanco@gmail.com X-Host-Fingerprint: 209.85.214.179 mail-ob0-f179.google.com Received: from [209.85.214.179] ([209.85.214.179:34404] helo=mail-ob0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AF/0A-39202-BB80AB65 for ; Tue, 09 Feb 2016 10:41:47 -0500 Received: by mail-ob0-f179.google.com with SMTP id wb13so190802680obb.1 for ; Tue, 09 Feb 2016 07:41:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=Wu8Lzf3vnf38GMgiv9ECkeqf903ZD2kf/EEbM2uy1WY=; b=FvKWXugOKryBf3lTzDzROBkGbM5KkeYj/E88/gi6MnQrvpz4CUbQZACJ1cKk4oUgra SxdAzibKnmNFYsnyqHHr2q7BTP1Kc3qMzmjELdyctjze77uuRl1Y44wXC+TVrm0ypvPj Q7pt8MXIdyzuFuOtdoOj+UzZd/RCtgXAj/BYceqsedkXzsIxc9ALq3hp5aS1gKfaA9Bu sxH53UHxfG/f38alnaZrQjh59VVWpH3cUPSddm8QynIPa2LmAqGaJZ+JLI8XoaQGwzjP R3TgdrGQaDAhOgXuR/Q0+STBE6KmtIHvOZ/ebHyLzwOVN+OAg/DU54qKYmvx0ERyvz1I Z+1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=Wu8Lzf3vnf38GMgiv9ECkeqf903ZD2kf/EEbM2uy1WY=; b=ccknwkWZit1Q1uQGwAME+cDSz1C81Ro8RvoDuFiC2ksZrreWMhsUANy6C43KCfEuja 9VPFfydBJ1x2KjR5y7UMctkTlSfCYC9TdRJblEXWt/GlsvUry15v1iNUnWk1AiyMyJFN qYMLR2J/0GkbzuAuF6Sltb1Vi3zLNtbJi3ynOg72DgJk3z0fBRH9vZbCybQoewUFTrh8 xyuUbnNsfEVwoGDNyIDeLOdNiqvwY3CUwzP0eNXUcNnNxJlP7KuSK9j/5yDes2EFOjBF B6EPtXBKLJOpX7id58mUZHDJDhsjkci22xkpygH2++pk7VkKRyXaxgcGVIso5FdKg10r 1s2A== X-Gm-Message-State: AG10YOSld+u/6JD74qkL4jGU8sEHxjDLbb1R+G1ubyLnj8po0S7if53zIDL0XQNnwxRG8IXVAO3sv7aw3cH5Pg== X-Received: by 10.182.142.170 with SMTP id rx10mr31025527obb.34.1455032504412; Tue, 09 Feb 2016 07:41:44 -0800 (PST) MIME-Version: 1.0 Received: by 10.76.86.1 with HTTP; Tue, 9 Feb 2016 07:41:25 -0800 (PST) In-Reply-To: References: <56B8D3D9.3040904@mprelu.de> Date: Tue, 9 Feb 2016 10:41:25 -0500 Message-ID: To: Matthew Setter Cc: Matt Prelude , piere.php@gmail.com, francois , gen.work@gmail.com, =?UTF-8?Q?Kinn_Coelho_Juli=C3=A3o?= , PHP internals Content-Type: multipart/alternative; boundary=001a11c338b28ff084052b582709 Subject: Re: [PHP-DEV] Proposal for a new array function From: guilhermeblanco@gmail.com ("guilhermeblanco@gmail.com") --001a11c338b28ff084052b582709 Content-Type: text/plain; charset=UTF-8 My personal take on this: Let's add just more 1 function over a 99999 function's array API, because I want to optimize 3 lines in my PHP code, and language lack of Generics while we still refuse to carefully think about a proper OO Collection API. Regards, On Tue, Feb 9, 2016 at 6:19 AM, Matthew Setter wrote: > Thanks kindly for the rapid and very helpful feedback. I'm going over it > today and will collate it and think over it further. Given that the > feedback's been so constructive and positive, I'll be getting started on an > RFC over the next day or so. > > Matt > > > -- > Kind regards, > > > *Matthew Setter* > *Freelance Software Developer & Technical Writer * > *Host of Free the Geek | Author of Zend Framework > 2 > Foundations * > > w: http://www.matthewsetter.com > t: *@settermjd * > g+: *+MatthewSetterFreelanceWriterDeveloper > >* > li: *in/matthewsetter * > > On Mon, Feb 8, 2016 at 6:43 PM, Matt Prelude wrote: > > > Hi, > > > >> I want to propose a new PHP array method, called has_numeric_keys (or > >> something similar/better), that would have the following method > signature: > >> > >> bool has_numeric_keys(array $array) > >> > >> The reason for it is to check if the array passed to it only had numeric > >> keys. > >> > >> Why this method, when you could do it in userland PHP? Answer? > >> Convenience. > >> I found, recently, that I had to perform this kind of check, when > patching > >> Zend\Db\Sql\Insert.php. The approach I took was this: > >> > >> return array_keys($arr) !== range(0, count($arr) - 1); > >> > >> Not sure of my approach, I took to Twitter and received the following > >> suggestions, amongst others: > >> > >> function isArrNum($arr) { > >> foreach($arr as $i =>$v){ > >> if (!is_int($i)) { > >> return false; > >> } > >> } > >> return true; > >> } > >> > >> count(array_filter(array_keys($array), 'is_string')) > 0 > >> > >> array_filter([...], 'is_int', ARRAY_FILTER_USE_KEY) > >> > >> This convinced me that it wasn't just me seeing a valid use case for it, > >> and that others have implemented differing solutions when presented with > >> the same situation. Given that, I believe a simple, utility, function > such > >> as this would be of help. > >> > >> As for who would implement it, that would be me. > >> > > I like it. Would like to see it be a bit more generic though, something > > like (ignore the name, I can't name functions): > > > > array_validate_keys($array, is_int); > > > > I say this because it allows for more potential uses (that and I've done > > exactly the same to check all keys are strings before). > > > > - Matt. > > > > > -- Guilherme Blanco MSN: guilhermeblanco@hotmail.com GTalk: guilhermeblanco Toronto - ON/Canada --001a11c338b28ff084052b582709--