Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97960 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22749 invoked from network); 25 Jan 2017 14:05:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Jan 2017 14:05:38 -0000 Authentication-Results: pb1.pair.com header.from=cmbecker69@gmx.de; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=cmbecker69@gmx.de; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.de designates 212.227.17.22 as permitted sender) X-PHP-List-Original-Sender: cmbecker69@gmx.de X-Host-Fingerprint: 212.227.17.22 mout.gmx.net Received: from [212.227.17.22] ([212.227.17.22:62746] helo=mout.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D3/E0-00729-1B0B8885 for ; Wed, 25 Jan 2017 09:05:38 -0500 Received: from [192.168.2.109] ([217.82.227.219]) by mail.gmx.com (mrgmx102 [212.227.17.168]) with ESMTPSA (Nemesis) id 0Mg0IT-1ctouU0fe1-00NNVa; Wed, 25 Jan 2017 15:05:31 +0100 To: Giovanni Giacobbi , PHP Internals List References: Message-ID: Date: Wed, 25 Jan 2017 15:05:39 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:m/H42kjTNxMIwsvkC5CFeXjGCk4HOFcbcJmHqfT/aysfGHczewy z8oXsxq/vg3dt66/yFCgKsSN6OddHE371i7qlfMuQH689zvZCJEdtvNkHoyTb2Js+V8sHQB l/dTOV2VIr6X2zBbmZnMUJnAl7Ud3Rzk2gr3xcaq/xdoutPQ7Fk/X93UfwfG0AZMGlmQGzU 724SHhTmGJz+/UCtm3iwg== X-UI-Out-Filterresults: notjunk:1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EKTEX6wkSso/twucDhjuND4NrUEOp4MC7seC/6TKS2nrI+Ic6xy8Q== Subject: Re: String to array odd behaviour in 7.1 From: cmbecker69@gmx.de ("Christoph M. Becker") On 25.01.2017 at 14:21, Giovanni Giacobbi wrote: > Greetings, > > There is something weird with 7.1 and implicit strings to array > conversions, so I wanted to double check with you that the behaviour is > wanted (and perhaps the migration71 doc should be updated to reflect this. > > So in the migration docs [1] you say that: " Applying the empty index > operator to a string (e.g. $str[] = $x) throws a fatal error instead of > converting silently to array. " > > I'm going to show four cases on different PHP versions: > > CASE 1: php -r '$a = "foo"; $a[] = "bar"; var_dump($a);' > PHP 5.6.x -> Fatal Error > PHP 7.0.x -> Fatal Error > PHP 7.1.x -> Fatal Error > > CASE 2: php -r '$a = "foo"; $a["x"] = "baz"; var_dump($a);' > PHP 5.6.x -> string "boo" (with illegal offset warning) > PHP 7.0.x -> string "boo" (with illegal offset warning) > PHP 7.1.x -> string "boo" (with illegal offset warning) > > CASE 3: php -r '$a = ""; $a["x"] = "bar"; var_dump($a);' > PHP 5.6.x -> array("x" => "bar") with NO warnings > PHP 7.0.x -> array("x" => "bar") with NO warnings > PHP 7.1.x -> string "b" with illegal offset warning > > CASE 4: php -r '$a = ""; $a[] = "bar"; var_dump($a);' > PHP 5.6.x -> array("bar") with NO warnings > PHP 7.0.x -> array("bar") with NO warnings > PHP 7.1.x -> Fatal Error > > I think what is bugging me here is that the docs talk about CASE 1 whose > behaviour actually did not change, so it should mention "empty string" > because that's where the actual change happened (CASE 4), also I think that > CASE 3 should be rethinked. > > In general I would like to raise a concern on the fact that I think the > previous behaviour was better, after all PHP is dynamically typed so why > not allow a variable to silently change its value silently? We know that > using offset with strings is always illegal (CASE 2) so why not *always* > converting it to an array and discard its previous value? > > [1] > http://php.net/manual/en/migration71.incompatible.php#migration71.incompatible.empty-string-index-operator See . -- Christoph M. Becker