Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:73258 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 13468 invoked from network); 18 Mar 2014 06:17:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Mar 2014 06:17:21 -0000 Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.170 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.220.170 mail-vc0-f170.google.com Received: from [209.85.220.170] ([209.85.220.170:43794] helo=mail-vc0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 08/59-17561-0F4E7235 for ; Tue, 18 Mar 2014 01:17:21 -0500 Received: by mail-vc0-f170.google.com with SMTP id hu19so6823613vcb.29 for ; Mon, 17 Mar 2014 23:17:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=7BzysPlAh0R+TpOwi5raTH/hNWEjj26my0okHndtiOU=; b=gK9sQesQZP+PYwQr7ltF46v1IWIhKmeD3s5s+719kUHVeZa+AOxuY0/SBwQ7gn1VYA zEcoRq3asUCyMm2bmsaZA4ULSwqdQUosM/mmBls3PZARIO1kfTplkH6CFiY39A5iZKqr LR/8L4vqcCoNOdMNvUjrhINX2ccFzG4LJMgBXuaurNn7IookhuDsJnj56IjhRipWg5Fn kyGja1md0GOlrloTR742MKUmEbDpHHwmYoG/qdkzqDfEfM/4FwPvz9xJprRgDDmqo0/A JOXOiA6fAdPharID14zwyFUNtQA99GbG/jdw/+bOTpZAvNWgknYuBA1BhQirQeZ+XUPq rBvQ== MIME-Version: 1.0 X-Received: by 10.220.249.6 with SMTP id mi6mr1131396vcb.33.1395123438269; Mon, 17 Mar 2014 23:17:18 -0700 (PDT) Received: by 10.58.55.131 with HTTP; Mon, 17 Mar 2014 23:17:18 -0700 (PDT) Date: Tue, 18 Mar 2014 14:17:18 +0800 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary=089e013a062cf4bcf304f4db7cb2 Subject: Re: Array dereference on scalar / null values From: tjerk.meesters@gmail.com (Tjerk Meesters) --089e013a062cf4bcf304f4db7cb2 Content-Type: text/plain; charset=ISO-8859-1 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`? Best, Jack --089e013a062cf4bcf304f4db7cb2--