Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:56508 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 24983 invoked from network); 23 Nov 2011 14:54:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Nov 2011 14:54:48 -0000 Authentication-Results: pb1.pair.com smtp.mail=tyra3l@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tyra3l@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.42 as permitted sender) X-PHP-List-Original-Sender: tyra3l@gmail.com X-Host-Fingerprint: 209.85.216.42 mail-qw0-f42.google.com Received: from [209.85.216.42] ([209.85.216.42:57365] helo=mail-qw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EF/04-31179-6390DCE4 for ; Wed, 23 Nov 2011 09:54:47 -0500 Received: by qabg40 with SMTP id g40so2698209qab.8 for ; Wed, 23 Nov 2011 06:54:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=5WX6e4uiBVJ4NjwAFz6mFyjoir0mNCgMJphhgG4pgQY=; b=U+cuTQfa2oCxmbdJqanxmJ0gWL4oWrUqNwQPa5o/mxCpsSkCmKwE7qZ9zIPN+ZJ9NH pAVRe3BovGYeXH4UOggaEdbtVqiPVetQqUVuhhZSfBDYAY/q4K0fUjBcts1BS2P3IK90 vb1b7Qz7CpMtxfW1YJNH/byT9iRfGQ4Q5z+zU= MIME-Version: 1.0 Received: by 10.224.189.11 with SMTP id dc11mr24358qab.35.1322060084163; Wed, 23 Nov 2011 06:54:44 -0800 (PST) Received: by 10.229.38.134 with HTTP; Wed, 23 Nov 2011 06:54:43 -0800 (PST) In-Reply-To: References: <20111123015008.GA12933@panix.com> <20111123023108.GA172@panix.com> <4ECCB549.904@lsces.co.uk> <4ECCBC56.3050602@sugarcrm.com> <20111123141408.GA11940@panix.com> Date: Wed, 23 Nov 2011 15:54:43 +0100 Message-ID: To: Gustavo Lopes Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=20cf303346bfb0354204b2681968 Subject: Re: [PHP-DEV] 5.4 regression: non-existent sub-sub keys now have values From: tyra3l@gmail.com (Ferenc Kovacs) --20cf303346bfb0354204b2681968 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Wed, Nov 23, 2011 at 3:42 PM, Gustavo Lopes wrot= e: > Em Wed, 23 Nov 2011 14:19:42 -0000, Ferenc Kovacs > escreveu: > > On Wed, Nov 23, 2011 at 3:14 PM, Daniel Convissor < >> danielc@analysisandsolutions.**com > >> wrote: >> >> > It's actually very simple. Take variable $a which is a string >>> > ("foo"). Now it you do $a[0] that would produce first letter - "f". >>> > Now here's a tricky part - if you do $a['blah'] it would convert >>> > 'blah' to number, get 0 and return the same letter "f". >>> >>> To me, this is the bug. $a['blah'] does not exist. An undefined index >>> notice should be raised. The key "blah" should not be converted to 0. >>> The following two things should behave the same: >>> >>> $b =3D array('exists' =3D> 'foo'); >>> echo $b['blah'] . "\n"; >>> >>> $a =3D 'foo'; >>> echo $a['blah'] . "\n"; >>> >>> But that second one echos out "f". This is a huge WTF. >>> >> >> >> and the following should also behave the same: >> $a =3D 'foo'; >> >> echo $a[2]; >> echo $a['2']; >> echo $a['2 cats']; >> >> because this is how the type juggling works in php: >> http://php.net/manual/en/**language.types.type-juggling.**php >> >> > But this is *not* (and afaik has never been) how indexes in arrays work. > The conversion of array keys has always different rules: > > $a['2 cats'] =3D null; > var_dump($a); > ^D > array(1) { > ["2 cats"]=3D> > NULL > } > yeah, because using associative arrays (hence strings as indexes) is a sane operation. but we are talking about strings here. > > The mapping between strings and integers used for arrays is 1 to 1, and > strings that can be mapped to integers are always mapped (so you cannot > have a '1' (string) key and a 1 (int) key). These different rules are wha= t > makes possible to store any kind of string in an array, and changing this > would be a huge error. > > I see, however, that it's not the case for indexing strings, where the la= x > rules are followed: > > $a =3D 'foo'; > var_dump($a['2 cats']); > ^D > string(1) "o" > > If there's any change to be made, it would be to change the way string > indexing works, not the other way around. > > php.net/manual/en/language.types.string.php#language.types.string.substr "Non-integer types are converted to integer." So it is a documented behavior, so the current change is just a bugfix imo. --=20 Ferenc Kov=C3=A1cs @Tyr43l - http://tyrael.hu --20cf303346bfb0354204b2681968--