Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:73299 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 75606 invoked from network); 19 Mar 2014 09:21:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Mar 2014 09:21:50 -0000 Authentication-Results: pb1.pair.com header.from=are.you.winning@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=are.you.winning@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.174 as permitted sender) X-PHP-List-Original-Sender: are.you.winning@gmail.com X-Host-Fingerprint: 209.85.216.174 mail-qc0-f174.google.com Received: from [209.85.216.174] ([209.85.216.174:59055] helo=mail-qc0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 85/42-58554-CA169235 for ; Wed, 19 Mar 2014 04:21:49 -0500 Received: by mail-qc0-f174.google.com with SMTP id c9so3373799qcz.19 for ; Wed, 19 Mar 2014 02:21:46 -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:date:message-id:subject :from:to:cc:content-type; bh=t6zMtfewxcNRYwh4CZOHx/Og/5sNuyA8PxJSM+5mIZY=; b=KfUKoOPmJjJ6QFJ6W4Bl1Q8sF2fyBvogpOBTHMYzDTHWPVwUqMdPD3CP7crfd/dNA9 syWfYCJeEwZfD8h+2yh0O9+UuK5jjGwFz6XGWbAA+/mur0oYiQk9Wc7q1o9oJCkymlVu NQXYBhsV0jniIQjgCn4KOvuPZwCm76GKWPKLCQDbQlaGqml07wrXWAy13s3bwJXUKYty iUitHTEs4q7+NqUP9yT/Gi6SGk/TLkePOYu7Yx+ngJtpUs2K14zmTaXnr3WGVKJ2Fc/E Chn9gef7MU/t2qL2piiHPfSVD4setG0193u6HhR8Ycbqi1yH3iVEDd1xxRowXMBoFBQK vBKg== MIME-Version: 1.0 X-Received: by 10.224.168.203 with SMTP id v11mr41853538qay.57.1395220906119; Wed, 19 Mar 2014 02:21:46 -0700 (PDT) Sender: are.you.winning@gmail.com Received: by 10.229.148.194 with HTTP; Wed, 19 Mar 2014 02:21:44 -0700 (PDT) Received: by 10.229.148.194 with HTTP; Wed, 19 Mar 2014 02:21:44 -0700 (PDT) In-Reply-To: References: Date: Wed, 19 Mar 2014 09:21:44 +0000 X-Google-Sender-Auth: vvjPBKcenGd1HHGnl9NyRY1_dvM Message-ID: To: Tjerk Meesters Cc: PHP Internals Content-Type: multipart/alternative; boundary=089e0149d2f67e173604f4f22e50 Subject: Re: [PHP-DEV] Re: Array dereference on scalar / null values From: cw@daverandom.com (Chris Wright) --089e0149d2f67e173604f4f22e50 Content-Type: text/plain; charset=ISO-8859-1 On 18 Mar 2014 06:17, "Tjerk Meesters" wrote: > > Hi internals, > > I've done some bug report gathering on essentially the following behaviour: > > $a = 123; var_dump($a[1]); // "NULL" > $b = true; var_dump($b[1]); // "NULL" > $f = fopen('file', 'r'); var_dump($f[1]); // "NULL" > $n = null; var_dump($n[1]); // "NULL" > > Bug reports: > > https://bugs.php.net/bug.php?id=37676 > https://bugs.php.net/bug.php?id=40692 > https://bugs.php.net/bug.php?id=62769 > https://bugs.php.net/bug.php?id=64194 > https://bugs.php.net/bug.php?id=65484 > > From the comments it seems that there's some disagreement within the group, > for example: > > Nikita: "I would tentatively classify this as a bug." > Tony: "Reclassified as feature request.." > Xinchen: "there was a similar bug report of this behavior, and I seems made > a fix for it." > Ilia: "this is not a bug." x 2 > Joe: "it is the only reasonable thing _to expect_" > > From my understanding, developers are expecting to see notices when this > happens, something like "Cannot use integer/boolean/resource/null as array > in %s on line %d"; I think they're okay with the fact that the end result > will still be "NULL", though. > > The `list()` operator has since complicated matters; if we would indeed > introduce notices as requested, the following code would cause issues: > > $array = [1, 2, 3]; > while (list($key, $value) = each($array)) { > echo "$key = $value\n"; > } > > The return value of `each()` - as it has reached the end of an array - is > `false`, so the above code would show two notices. Unfortunately, we must > assume that all code in the manual are actually used and so it would surely > break stuff when introduced. > > We could mitigate this issue by having `each()` return `null` instead and > introduce notices for all other scalars, but this code is not unlikely: > > while (($data = each($array)) !== false) { > echo "${data[0]} = ${data[1]}\n"; > } > > So my question is, how should we handle this? Close all bug reports and add > something to the documentation? Allow array dereference only on booleans > *and* `null`? > The alternative is treating list() as the special case and suppressing the error there. I'd prefer this over allowing bool/null to be dereferenced silently in the general case, since it would keep the special handling where it belongs - I.e. where the conflict is. > > Best, > Jack --089e0149d2f67e173604f4f22e50--