Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:56506 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 21644 invoked from network); 23 Nov 2011 14:42:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Nov 2011 14:42:48 -0000 Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.21 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.21 smtp1.ist.utl.pt Linux 2.6 Received: from [193.136.128.21] ([193.136.128.21:58176] helo=smtp1.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AD/63-31179-5660DCE4 for ; Wed, 23 Nov 2011 09:42:46 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp1.ist.utl.pt (Postfix) with ESMTP id 6954D70003FE for ; Wed, 23 Nov 2011 14:42:42 +0000 (WET) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp1.ist.utl.pt ([127.0.0.1]) by localhost (smtp1.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id DVgzMu-f6pZi for ; Wed, 23 Nov 2011 14:42:42 +0000 (WET) Received: from mail2.ist.utl.pt (mail.ist.utl.pt [IPv6:2001:690:2100:1::8]) by smtp1.ist.utl.pt (Postfix) with ESMTP id 23B3C70003C3 for ; Wed, 23 Nov 2011 14:42:42 +0000 (WET) Received: from clk-0081.mshome.net (unknown [85.139.253.17]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id F086B2008AF6 for ; Wed, 23 Nov 2011 14:42:41 +0000 (WET) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: internals@lists.php.net 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 14:42:41 -0000 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Organization: =?utf-8?Q?N=C3=BAcleo_de_Eng=2E_Biom=C3=A9di?= =?utf-8?Q?ca_do_I=2ES=2ET=2E?= Message-ID: In-Reply-To: User-Agent: Opera Mail/11.52 (Win32) Subject: Re: [PHP-DEV] 5.4 regression: non-existent sub-sub keys now have values From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") 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 = array('exists' => 'foo'); >> echo $b['blah'] . "\n"; >> >> $a = '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 = '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: NULL } 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 what 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 lax rules are followed: