Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98388 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5673 invoked from network); 2 Mar 2017 22:39:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Mar 2017 22:39:18 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.47 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.47 mail-wm0-f47.google.com Received: from [74.125.82.47] ([74.125.82.47:35969] helo=mail-wm0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4D/9A-20342-51F98B85 for ; Thu, 02 Mar 2017 17:39:17 -0500 Received: by mail-wm0-f47.google.com with SMTP id n11so2822320wma.1 for ; Thu, 02 Mar 2017 14:39:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=XUNs5B8jVhawDnJbHOwAf8ubp9Nh3ukT5CPMTeXjyoY=; b=pEhGtuJsad+Oh1Nb+tlpxWDEnMgzh9s+1hsva3rwO6E86yzRZ7b+FrRZ54wp1yPFHk EpmgzcTFJQwvi1BDN6JqWCFQrGV4HmAEycxsafGhGxewT/AHmnbvaxKqChSB9bulnlqc pi1fp3Hr99uHg4oHlRBDZzuwcdRy8fl7SJGiIYoW2e8ut3ECpWg01aKvRX98/8WEXosl lC+R3xl3bdfXh9ZuolKlqf5emGsxGHntGa5Gs4z4MFzjXR00YnO6tM43ECxPt/EFqmiy sYWbWhBgUrhY85EB79P9JcNPmTRwmPEmp93cZfBNw6XdZqEKGf69/VSgG7ZN7TijOg70 LbNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=XUNs5B8jVhawDnJbHOwAf8ubp9Nh3ukT5CPMTeXjyoY=; b=AqUgzd/RHN8MwMyRBcTVuqOmQ2RmaOYy5HH/RZa+zoDs8flVV3lO6ujLWve0ViS98h jNwLlYA9l3FJUBMNQnLDc46QEmVBWY5K2BpdCVAZu+r2IygslU3D1SCsuuIzx3tpRRYo Q0lBj7hjItUhElYPr4KDynWx2snYcPsP+E4R4CvogMOCfC6FT6dXZRqCVRI76nLeVHsB PHzoQTNw36tFgeVu5kZ1ttV2flFIkHSY80w9PFD8vhp8rRZWNgi0OiJaEHyfTd+IzDKr TnK/N+q+kfoMqsAFpwzanEhj5GOqfIQlTsS3CqJ3WV1ooEYMZ/yxGd+2DZDl/f3sxX7o sHPQ== X-Gm-Message-State: AMke39mhmA7AUsaIyt5Qc6EFb/g1mAEBfSpbCkVShM30FaWZYajk5l2l3FFR1ur1XEE83w== X-Received: by 10.28.168.75 with SMTP id r72mr442635wme.34.1488494354045; Thu, 02 Mar 2017 14:39:14 -0800 (PST) Received: from ?IPv6:2a00:23c4:4bd2:6e00:5d67:b495:d045:f476? ([2a00:23c4:4bd2:6e00:5d67:b495:d045:f476]) by smtp.googlemail.com with ESMTPSA id o63sm405160wmo.30.2017.03.02.14.39.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Mar 2017 14:39:13 -0800 (PST) To: internals@lists.php.net References: Message-ID: <3d5cfa50-5f5d-5633-99ad-052a6b5ac599@gmail.com> Date: Thu, 2 Mar 2017 22:39:13 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.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] Re: On arrays starting with a negative index From: rowan.collins@gmail.com (Rowan Collins) On 01/03/2017 20:46, Pedro Magalhães wrote: > As a clarification, the current implementation of the PR affects arrays in > general, not only array_fill. Any array that starts with a negative index > would continue from that index instead of 0. Meaning that [-2 => true, > true, true] would now return [-2 => true, -1 => true, 0 => true] instead of > [-2 => true, 0 => true, 1 => true]. Hi Pedro, Would other behaviour also be affected? For instance: $foo = [ -2 => true ]; $foo[] = true; $foo[] = true; var_dump($foo); If so, this is a much wider BC break; if not, why not? Currently, this is completely consistent: https://3v4l.org/hXAsf Indeed, I would say this is the missing explanation of why array_fill works the way it does. Presumably, this is why there is a note on the manual page: > See also theArrays section of manual for a detailed explanation of negative keys. Although as pointed out by Andrew Nester, this "detailed explanation" doesn't actually seem to exist. This seems to be the closest we get: > As mentioned above, if no key is specified, the maximum of the existing integer indices is taken, and the new key will be that maximum value plus 1 (but at least 0). If no integer indices exist yet, the key will be 0 (zero). Hidden in that first rambling sentence is the key phrase "but at least 0"; and the second should really say "If no positive integer indices..." [It shouldn't say "exist", either, because as the next paragraph explains, it can actually be affected by keys that no longer exist; which I'd never actually realised before!] This deserves to be a full section rather than a note, and much more clearly articulated. It might even make sense to split that page into sub-pages in some way, but I'm drifting into a different discussion, for a different list. The point right now is that array_fill's behaviour is actually consistent with the rest of the language, and while the value of that behaviour is questionable, changing it now would be a major decision. Regards, -- Rowan Collins [IMSoP]