Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93625 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20475 invoked from network); 29 May 2016 17:40:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 May 2016 17:40:39 -0000 Authentication-Results: pb1.pair.com header.from=colinodell@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=colinodell@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.47 as permitted sender) X-PHP-List-Original-Sender: colinodell@gmail.com X-Host-Fingerprint: 209.85.218.47 mail-oi0-f47.google.com Received: from [209.85.218.47] ([209.85.218.47:34769] helo=mail-oi0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C8/33-23584-6992B475 for ; Sun, 29 May 2016 13:40:39 -0400 Received: by mail-oi0-f47.google.com with SMTP id b65so241716902oia.1 for ; Sun, 29 May 2016 10:40:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ogx3sa1hoxv/qHd3AnzPGD/gVl59Udzd0r/ps0Yt/yc=; b=mNqxMgE1eMdOa0yn3yZrtY7LRXEJnaugrFB1y0YZM6kxbFn15v8oQp4Dma6710VVjh vTxnqyiZ8BehVh8rI4BDpnqIrC6SQ8MiP/NGsq/PyjzYOs3EzAYfmTTzrJARv7rTCS8u /EwLxbpDWoiwi76uPe42jl8e4CUt1XC+XtIpNqYQo0rkSdWqk9BYmorH0pwF8Ynb4aOh oVEHAV4CjqatL1uwMua6TzkxN8/kcfog967BgStAUuJJI0UhCuI7ZyL0uWjxy5NeeOS3 bfZQ7htknh0kzPmqPCVNIMmDh64Afs8jCW/G2nAAD7xcY0F39z+qIGmGltq6E2OupKdp R1Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ogx3sa1hoxv/qHd3AnzPGD/gVl59Udzd0r/ps0Yt/yc=; b=iocGidM/UHKE6X20x54myHc2XsD/z8PmT+mT0To0J+WZ5WOqq4fszyEAtWE9DbX6oV tvkHgBHSnBR8FMKIXLQ/W0k715ukfac9lsucUp+rrf/LcQLwMmrO+7UuivZ650FDI7h/ 3KpWdIz5hxBeGmFgNy/xKi4XFot6bdO6YfiCzZq9wDKupv+cM7x0FCTIGXQoqs7hHnEc jApvQsTnsNqH3vzsrK3vCEoGLjABo71qhxV4X3mKgmca54JTERaLzGV6u2WTa5e5MEiB EK4s2r1daYJBAee6jbe0x0aaBn1SZgnsmY3DQbC9acxQG1rxC1pRK26gA3DnqN7S9Wke n24w== X-Gm-Message-State: ALyK8tIBUBXrCRSClGuT2pEGjFVQXVbzQdlXP8s8B8v7ZR7voxFIgK1X0oWqJMmIrZNw/gdsGbECG5WS6drMOQ== X-Received: by 10.202.77.129 with SMTP id a123mr13401017oib.143.1464543636217; Sun, 29 May 2016 10:40:36 -0700 (PDT) MIME-Version: 1.0 References: <574AF60A.6070908@nunninger.info> In-Reply-To: <574AF60A.6070908@nunninger.info> Date: Sun, 29 May 2016 17:40:26 +0000 Message-ID: To: Thomas Nunninger , PHP Internals Cc: jmikola@gmail.com Content-Type: multipart/alternative; boundary=001a113de8de31e3750533fea34f Subject: Re: [PHP-DEV] [RFC Discussion] array_change_keys() From: colinodell@gmail.com ("Colin O'Dell") --001a113de8de31e3750533fea34f Content-Type: text/plain; charset=UTF-8 > > shouldn't it be possible to return null as new key? That way you say: > Use the next free integer index. > > Not sure if returning null is wanted (as it could hide errors in the > callback) or needed in some real world use cases. But it would be more > in sync with $a[] = ... > That's an interesting idea, but it would go against how other array functionality works. For example, if you ran this: var_dump( array_combine([null, null], ['foo', 'bar']) ); You'd get the following output: array(1) { [""]=> string(3) "bar" } The null you intended to be a key becomes an empty string instead, and the latter value of "bar" overrides the former one. You'll see this same behavior if you did the following: $a = []; $a[null] = 'foo'; $a[null] = 'bar'; So that's one way nulls are handled. The other way is to raise a warning and skip that element, which is what array_flip (and this proposal) does: var_dump( array_flip(['foo' => 'null']) ); Output: Warning: array_flip(): Can only flip STRING and INTEGER values! in /in/7bBvO on line 3 array(0) { } Implementing the feature you mentioned would introduce a third approach, which is something I'd like to avoid. Perhaps a future RFC could implement this feature, either for just this one function or others as well? Colin --001a113de8de31e3750533fea34f--