Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87915 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66022 invoked from network); 25 Aug 2015 15:53:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Aug 2015 15:53:44 -0000 Authentication-Results: pb1.pair.com smtp.mail=php.lists@allenjb.me.uk; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=php.lists@allenjb.me.uk; sender-id=pass Received-SPF: pass (pb1.pair.com: domain allenjb.me.uk designates 85.119.82.103 as permitted sender) X-PHP-List-Original-Sender: php.lists@allenjb.me.uk X-Host-Fingerprint: 85.119.82.103 server2.alteredperspective.co.uk Received: from [85.119.82.103] ([85.119.82.103:44001] helo=mail.apserver.co.uk) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 74/70-62931-58F8CD55 for ; Tue, 25 Aug 2015 11:53:42 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.apserver.co.uk (Postfix) with ESMTP id 0783628C06A; Tue, 25 Aug 2015 17:02:15 +0100 (BST) Received: from mail.apserver.co.uk ([127.0.0.1]) by localhost (server2.alteredperspective.co.uk [127.0.0.1]) (amavisd-new, port 10024) with LMTP id TmbaoGezJWL2; Tue, 25 Aug 2015 17:02:13 +0100 (BST) Received: by mail.apserver.co.uk (Postfix, from userid 81) id 7804428C069; Tue, 25 Aug 2015 17:02:13 +0100 (BST) To: Sherif Ramadan X-PHP-Originating-Script: 501:rcube.php MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 25 Aug 2015 17:02:13 +0100 Cc: Nicolai Scheer , PHP Internals In-Reply-To: References: Message-ID: X-Sender: php.lists@allenjb.me.uk User-Agent: Roundcube Webmail/1.1.1 Subject: Re: [PHP-DEV] Notice on non existing array key (on a boolean) From: php.lists@allenjb.me.uk (AllenJB) I have a pull request pending on this bug: https://github.com/php/php-src/pull/1269 It's been discussed before ("Array dereferencing of scalars", 10th June 2015 - I'm pretty sure it was discussed at least once more since then too) and I was basically told it would require an RFC to get it accepted. Unfortunately the RFC window had basically closed at that time (and work got busy shortly after), so now I've been waiting until 7.0 is clear (as well as me having the time to finish drafting the RFC). AllenJB On , Sherif Ramadan wrote: > Hey Nicolai, > > You're right. The notice is triggered by array_push behavior only, > which > means that $x = true; echo $x['foo']; doesn't trigger the notice, which > is > the same as your code above. Only write operations have historically > resulted in this notice. > > I would agree that providing the notice would help someone debugging > potentially buggy code like this. Not sure if this is something we can > squeeze into 7.0.0 release at this point, but I would consider it a bug > fix > with BC rather than something that should be subject to current feature > freeze. > > > > On Tue, Aug 25, 2015 at 9:35 AM, Nicolai Scheer > > wrote: > >> Hi all, >> >> I'd expect the following code to throw a notice/warning: >> >> $x = true; >> $y = $x['foo']; >> >> It executes completely silently. >> $y is NULL afterwards, which is expected, since the right hand side of >> the assignment is undefined. >> >> If $x was an array (e.g. empty array), a E_NOTICE would be emitted. >> >> Can anyone shed a light on this behaviour? If accessing non existing >> array keys is worth a notice, shouldn't accessing an array index on a >> non array be worth a notice as well (maybe even a warning)? >> >> The other way round emits a warning (i.e. writing to an array key on a >> non array): >> >> $x = true; >> $x['foo'] = 'bar'; >> >> Warning: Cannot use a scalar value as an array ... >> >> Thanks for any insight, >> >> greetings >> >> Nico