Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87912 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52911 invoked from network); 25 Aug 2015 13:48:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Aug 2015 13:48:33 -0000 Authentication-Results: pb1.pair.com smtp.mail=theanomaly.is@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=theanomaly.is@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.54 as permitted sender) X-PHP-List-Original-Sender: theanomaly.is@gmail.com X-Host-Fingerprint: 209.85.215.54 mail-la0-f54.google.com Received: from [209.85.215.54] ([209.85.215.54:35735] helo=mail-la0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6D/F4-05482-F227CD55 for ; Tue, 25 Aug 2015 09:48:31 -0400 Received: by labgv11 with SMTP id gv11so30789237lab.2 for ; Tue, 25 Aug 2015 06:48:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=ySsByCt9vZ8zqdpe5lhu6Q1W1LATqVxT/0xOs9s0cVs=; b=gJD6/9GOcYJxv3sMgiCC/5zx4i9aNcVfz6fpM//TkJQLsTHgYXqnDc7D5XZqJfvC1x WibAqgzGjy8vNL7amzUYc06A15gYEw3BwYvcXkE/R/cw2xsW2abQkVhAHKWWdwhl5RYO HGQ5ilv3Q/M5Lvyci/r27T3fDoHggXd+uRiVWb1tQ8rkli6qWIbJ8arxud35oWUURA9u rvmQxZ8TBFXDAvdRoS0OUukTKFu+3VdHXlACpBAPgYaEYAbNl1xBnD1uJaHsEYU1NFQe gMHFXaKC2K8G9A7sI3AFJ8/68XFEDpevZMmeTjvCtGUBKluIQZxB7lcV6XO1RYPnEaas OTIA== MIME-Version: 1.0 X-Received: by 10.152.170.130 with SMTP id am2mr25951936lac.54.1440510508665; Tue, 25 Aug 2015 06:48:28 -0700 (PDT) Received: by 10.25.200.196 with HTTP; Tue, 25 Aug 2015 06:48:28 -0700 (PDT) In-Reply-To: References: Date: Tue, 25 Aug 2015 09:48:28 -0400 Message-ID: To: Nicolai Scheer Cc: PHP Internals Content-Type: multipart/alternative; boundary=089e011615682a100e051e22fdd5 Subject: Re: [PHP-DEV] Notice on non existing array key (on a boolean) From: theanomaly.is@gmail.com (Sherif Ramadan) --089e011615682a100e051e22fdd5 Content-Type: text/plain; charset=UTF-8 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 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --089e011615682a100e051e22fdd5--