Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86516 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 79341 invoked from network); 9 Jun 2015 11:55:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Jun 2015 11:55:16 -0000 Authentication-Results: pb1.pair.com smtp.mail=php_lists@realplain.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=php_lists@realplain.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain realplain.com from 216.33.127.80 cause and error) X-PHP-List-Original-Sender: php_lists@realplain.com X-Host-Fingerprint: 216.33.127.80 mta11.charter.net Solaris 10 1203 Received: from [216.33.127.80] ([216.33.127.80:37594] helo=mta11.charter.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7A/C1-00828-324D6755 for ; Tue, 09 Jun 2015 07:55:15 -0400 Received: from imp09 ([10.20.200.9]) by mta11.charter.net (InterMail vM.8.01.05.09 201-2260-151-124-20120717) with ESMTP id <20150609115512.QOLR5815.mta11.charter.net@imp09>; Tue, 9 Jun 2015 07:55:12 -0400 Received: from mtaout002.msg.strl.va.charter.net ([68.114.190.27]) by imp09 with smtp.charter.net id eBvC1q0070buw5Q05BvCKD; Tue, 09 Jun 2015 07:55:12 -0400 Received: from impout006 ([68.114.189.21]) by mtaout002.msg.strl.va.charter.net (InterMail vM.9.00.015.01 201-2473-143-101) with ESMTP id <20150609115512.KYYZ7014.mtaout002.msg.strl.va.charter.net@impout006>; Tue, 9 Jun 2015 06:55:12 -0500 Received: from pc1 ([96.35.251.86]) by impout006 with charter.net id eBvC1q0051sc0so01BvCqK; Tue, 09 Jun 2015 06:55:12 -0500 X-Authority-Analysis: v=2.1 cv=Mo3c6gqe c=1 sm=1 tr=0 a=Is5gsZaFXO8aPum+t7Tz+g==:117 a=Is5gsZaFXO8aPum+t7Tz+g==:17 a=hOpmn2quAAAA:8 a=N659UExz7-8A:10 a=BCPeO_TGAAAA:8 a=f95LKLS-If7ZIzG0fRgA:9 a=pILNOxqGKmIA:10 Message-ID: To: "Christoph Becker" , "Yasuo Ohgaki" Cc: "Stanislav Malyshev" , References: <5576051A.3040800@gmx.de> <55760771.6020802@gmail.com> <778F345F9918474AB8CAAB03082ECBF7@pc1> <5576CC2E.8080908@gmx.de> Date: Tue, 9 Jun 2015 06:55:12 -0500 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="Windows-1252"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5931 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Subject: Re: [PHP-DEV] Array dereferencing of scalars From: php_lists@realplain.com ("Matt Wilmas") Hi all, ----- Original Message ----- From: "Christoph Becker" Sent: Tuesday, June 09, 2015 > Yasuo Ohgaki wrote: > >> I fully agree that current behavior could be used meaningful ways. >> However, >> >> > $foo = 42; >> $foo['bar']; // => NULL >> $v = NULL; >> $v[0][1][2][3][4][5][6][7][8][9]; // NULL >> >> this code is semantically wrong and I would like to have error/exception >> for such >> erroneous codes. It's inconsistent with array object, too. >> >> Raising exception/error is correct behavior for types that aren't array. >> To avoid errors, users should use isset()/is_array()/etc. > > I agree that the code is not clean, and that an isset check is > appropriate, particularly as one could do: > > $v = NULL; > $v[0][1][2][3][4][5][6][7][8][9] ?? NULL; // NULL Forgetting the NULL case for a sec... With: $v = []; $v[0][1][2][3][4][5][6][7][8][9]; How/why are we going from 1 Notice to 10?! With: unset($v); $v[0]; Why from 1 Notice about the undefined variable, to 2? That's totally new, and it really doesn't make sense to make any more noise after you've already been told about the variable. (Same after the first undefined array offset, too, but this makes the point more obvious.) That's why I'm saying, you can only really change it for non-NULL scalars that have an actual value, to keep this other stuff the same, and sane. I don't really see a semantic issue with the NULL case, either, unlike other scalar types. >> Since we have debate for this PR, this PR would be good for RFC targeting >> PHP 7.1. > > It seems to me that raising an exception or throwing an error (instead > of a notice) could be too much of a BC break for a minor version. Just wondering, in the exception case, does that mean 10 exceptions also (one for each dimension)...? > -- > Christoph M. Becker - Matt