Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86514 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73155 invoked from network); 9 Jun 2015 10:45:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Jun 2015 10:45:42 -0000 Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.53 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.213.53 mail-yh0-f53.google.com Received: from [209.85.213.53] ([209.85.213.53:34755] helo=mail-yh0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D9/D0-00828-4D3C6755 for ; Tue, 09 Jun 2015 06:45:41 -0400 Received: by yhid80 with SMTP id d80so5265170yhi.1 for ; Tue, 09 Jun 2015 03:45:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=GMGcGXTaDD6ryUE3v6V63tL/KzWP5K87tOLE+VYJZ/o=; b=hTdNlYpho6dUm83kouvCcWzoC+TbDV1c7R4frhdx8D25QrJbPui2WwO2DzH9HVkqf1 eSedgH8Dn9vIuy+QrQ3Cqo30s5nPxH6f2rs7OxuyD2tpfMOaKQam8UELtxWHf3/sEAjA ZcQzNyI3lha+HdlEVDZzIYOSzy8uVUTdF7ZtjL+ZJYbXoj9zzyzDYl6RPA69IMeKLzJL G0qGRaxQnUMMIGKxgQy8cNE9q+PdmfC4POrP03TjGN4QKfhK604fc7n41CzzlBs64Pr8 uP/vt+2zgGYzyhPiBN5B+1+j5z7L1daDBlaq7bwaRESEDp/NsVWF+N647O17vGURODwL mRpA== X-Received: by 10.170.71.5 with SMTP id n5mr19563601ykn.85.1433846738275; Tue, 09 Jun 2015 03:45:38 -0700 (PDT) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.13.246.2 with HTTP; Tue, 9 Jun 2015 03:44:58 -0700 (PDT) In-Reply-To: <778F345F9918474AB8CAAB03082ECBF7@pc1> References: <5576051A.3040800@gmx.de> <55760771.6020802@gmail.com> <778F345F9918474AB8CAAB03082ECBF7@pc1> Date: Tue, 9 Jun 2015 19:44:58 +0900 X-Google-Sender-Auth: sgQrFrlvMyeqVaIH_kXvwdehpSk Message-ID: To: Matt Wilmas Cc: Stanislav Malyshev , Christoph Becker , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a1139e66c7f557205181375bf Subject: Re: [PHP-DEV] Array dereferencing of scalars From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a1139e66c7f557205181375bf Content-Type: text/plain; charset=UTF-8 Hi Matt, On Tue, Jun 9, 2015 at 7:04 PM, Matt Wilmas wrote: > Hi all, > > > ----- Original Message ----- > From: "Yasuo Ohgaki" > Sent: Tuesday, June 09, 2015 > > Hi all, >> >> On Tue, Jun 9, 2015 at 6:21 AM, Stanislav Malyshev >> wrote: >> >> > Would throwing a notice or a warning on array deferencing scalars >>> > be acceptable for PHP 7.0, or does this need an RFC? >>> >>> I think this does need an RFC, and for 7.0, pretty much no new language >>> changes are acceptable anymore, since we're past the timeframe. >>> >> >> >> > $foo = 42; >> $foo['bar']; // => NULL >> >> This code cannot be right. >> How about fix this as a simple bug? >> > > I just realized this behavior a couple months ago, after being annoyed by > "needing" to use isset() to avoid a Notice in rare cases. (I've always > hate, hate, hated the isset() mess just trying to assign stuff -- I wanted > a value-returning IFset() instead! Now we have ??, but still can't do > var_dump($var ??).) > > Anyway, I realized after checking the code that this is actually > intentional and always has been, it seems. Really glad that I could rely > on this and it makes things simpler and cleaner! :-) > > Note that I'm referring to accessing NULL as an array (that I'd like to > rely on). The other bool/int scalar without-a-notice case did/does seem a > bit odd. > > So if there's a change, how about only changing it for non-NULL values? > Otherwise, this: > > $v = NULL; $v[0][1][2][3][4][5][6][7][8][9]; > > is supposed to give 10 Notices?! That's dumb, and ugly, and looks like > what the Pull Request is doing with the updated tests. Even worse in the > case where the variable is undefined... > I fully agree that current behavior could be used meaningful ways. However, 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. Since we have debate for this PR, this PR would be good for RFC targeting PHP 7.1. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a1139e66c7f557205181375bf--