Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70251 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76518 invoked from network); 20 Nov 2013 21:49:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Nov 2013 21:49:36 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 198.187.29.241 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 198.187.29.241 imap3-1.ox.registrar-servers.com Received: from [198.187.29.241] ([198.187.29.241:53273] helo=imap3-1.ox.registrar-servers.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 66/24-51208-F6E2D825 for ; Wed, 20 Nov 2013 16:49:36 -0500 Received: from localhost (localhost [127.0.0.1]) by oxmail.registrar-servers.com (Postfix) with ESMTP id 37ADD2A009A; Wed, 20 Nov 2013 16:49:33 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap3.ox.registrar-servers.com Received: from oxmail.registrar-servers.com ([127.0.0.1]) by localhost (imap3.ox.registrar-servers.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id bE6Jp8NKLLUy; Wed, 20 Nov 2013 16:49:33 -0500 (EST) Received: from [192.168.0.13] (unknown [94.13.99.191]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by oxmail.registrar-servers.com (Postfix) with ESMTPSA id B09D82A00A2; Wed, 20 Nov 2013 16:49:29 -0500 (EST) Message-ID: <528D2E66.7090009@ajf.me> Date: Wed, 20 Nov 2013 21:49:26 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 To: Yasuo Ohgaki , Nikita Popov CC: "internals@lists.php.net" References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] fix bug #53432 (Assignment via string index access on an empty string converts to array) From: ajf@ajf.me (Andrea Faulds) On 20/11/13 21:38, Yasuo Ohgaki wrote: > Hi Nikita, > > On Thu, Nov 21, 2013 at 12:26 AM, Nikita Popov wrote: > >> The current behavior is that anything "falsey" (e.g. null, false and the >> empty string) is silently cast to array when an array operation is applied >> to it. I don't like that behavior, but it's somewhat internally consistent >> now. Changing it for strings *only* seems a bit weird. > > > Persuasive argument. > I prefer to change the behavior if I have to choose, though. > > $a = ''; // empty string > $a[10] = 'a'; > echo $a; // "Array" > Just my 2 cents, but that definitely looks like a situation that might crop up in real code unintentionally, and it violates the Principle of Least Astonishment IMO. Consider a hypothetical function which returns a modified string. If we've ended up with an empty string being passed into it, then it suddenly returning an Array is not what you expect, and might horribly break code that assumes the result won't be a string. -- Andrea Faulds http://ajf.me/