Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91129 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86724 invoked from network); 8 Feb 2016 17:53:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Feb 2016 17:53:50 -0000 Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 66.111.4.26 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 66.111.4.26 out2-smtp.messagingengine.com Received: from [66.111.4.26] ([66.111.4.26:60128] helo=out2-smtp.messagingengine.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9D/18-36326-C26D8B65 for ; Mon, 08 Feb 2016 12:53:49 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 5EB6B20316 for ; Mon, 8 Feb 2016 12:53:46 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Mon, 08 Feb 2016 12:53:46 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=6CeLA+RNjF71+Dn mZ73cK43SV8o=; b=SMyU9vUpbJ6b5Pys1gqoLb+fvDmMoJUgrBNLjWWk69wWTRf AuifAtwNPWlEgubfJKB/MCpZU/LfWJFkq4k/YAEoEDSCCd0FVZ2VNWFGGH221fMr xuuI06sSJhv0ujJ7UzrKRZ+lxQm16BR4g+IUL7FXtwJBpQDUvGtqtp5LId64= X-Sasl-enc: pzCwR93bBFkbRm8HVxxGy/nt0xvE3KAGqZHvIeizQeUY 1454954026 Received: from Crells-MacBook-Pro.local (unknown [63.250.249.138]) by mail.messagingengine.com (Postfix) with ESMTPA id 19CFA68010F for ; Mon, 8 Feb 2016 12:53:46 -0500 (EST) To: internals@lists.php.net References: <56B8C492.2060800@gmail.com> Message-ID: <56B8D629.3030305@garfieldtech.com> Date: Mon, 8 Feb 2016 11:53:45 -0600 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.0.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Proposal for a new array function From: larry@garfieldtech.com (Larry Garfield) On 2/8/16 11:46 AM, Kinn Julião wrote: > On Mon, Feb 8, 2016 at 11:38 AM, Rowan Collins > wrote: > >> Kinn Julião wrote on 08/02/2016 16:05: >> >>> That's the nice thing about userland... you are giving them ability to >>> implement what they want! >>> `array_filter([...], 'is_int', ARRAY_FILTER_USE_KEY)` does the job as the >>> others... don't think having a new function would prevent this. >>> >> It does the job, but it is much less efficient in some cases than the >> foreach and return false case, as it must examine every element; it also >> has unnecessary memory overhead, creating a filtered list which exists only >> to be counted and thrown away; and an internal implementation could be >> optimised even further by exploiting the way the engine stores the array >> internally. >> > How does `array_filter([...], 'is_int', ARRAY_FILTER_USE_KEY)` add that > *much* overhead? > And if that's the case, instead of introducing a 99999 array function into > the core, why not just create a new Object then? > > $list = list('foo','bar'); // I know it's a reserved token, don't have time > to find a better synonym. it's just a sample > $list[2] = 'baz'; > > var_dump($list); > > string(1) "foo" > string(1) "bar" > string(1) "baz" > > $list['a'] = 'foobar'; // Fatal error. I'm confused at the goal here. Is the intent "I need to do different logic if this is a numeric array vs. something else" or "I need to make sure this is a numeric array, because things break otherwise"? If the latter, $foo = array_values($bar); is a reasonably efficient and reasonably bulletproof way to ensure you have a strictly numeric array. >> PHP is at this stage expressive enough that a large number of core >> functions could be rewritten in multiple ways using other core functions, >> but that doesn't automatically rule out adding more functions to core where >> it is useful to do so. > > PHP is at a stage where we can add support to a better structure and > objects support... we don't need a function to check if the keys are > integer, we need an object that only supports integer as keys, or even a > generic key... > > Would rather have `Map` than `has_numeric_keys` Or that. Which I like even better. Ahead-of-time typing is much safer at scale than runtime typing. (Of course we then run smack into the arrays-and-objects-are-just-different-enough-to-be-annoying problem that has plagued us for a decade.) -- --Larry Garfield