Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86517 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84319 invoked from network); 9 Jun 2015 12:30:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Jun 2015 12:30:39 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.171 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.171 mail-wi0-f171.google.com Received: from [209.85.212.171] ([209.85.212.171:38738] helo=mail-wi0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5F/A2-00828-F6CD6755 for ; Tue, 09 Jun 2015 08:30:39 -0400 Received: by wibdq8 with SMTP id dq8so14982328wib.1 for ; Tue, 09 Jun 2015 05:30:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=vYhM/++ysfSoR16zJ9eWoNyGYC72QA4eJP1wyUW50MM=; b=EJHKfRRVy/cLcO2bKCtkQbVYvK8Z9jktOBKVFbrnW0aMc0X5R6YEhC5jtk4QGqx3yk WytFGVF48KQYZ4Z3T4PeqHWTNB74hwVCsvCK+GnHULZ1dtvYjHjJJxp5EeZixHkHe/i3 rVW0lvwduPgYqsfEnYbPsuPe+s+vyxvkJGvI+tuXEGvdcwnJ2MyqvWwuMjWs5TqhqEEs DicFfeHrw3PrsMOmUkjlbF4KIP3Inlq/CJGq56ToZ/O2cyGWuJiw2uYFVx7l8DaYi2lo 1svwSWXHPdlcNQOB9DQKB0SMVA1cJPOn3yWfHI685bwu33vBn1OZaSnbcvALkzsoJN1h b4ZQ== X-Received: by 10.180.82.135 with SMTP id i7mr8144233wiy.68.1433853036237; Tue, 09 Jun 2015 05:30:36 -0700 (PDT) Received: from [192.168.0.159] ([62.189.198.114]) by mx.google.com with ESMTPSA id gs7sm2645221wib.10.2015.06.09.05.30.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Jun 2015 05:30:35 -0700 (PDT) Message-ID: <5576DC09.8050705@gmail.com> Date: Tue, 09 Jun 2015 13:28:57 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: internals@lists.php.net References: <5576051A.3040800@gmx.de> <55760771.6020802@gmail.com> <778F345F9918474AB8CAAB03082ECBF7@pc1> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Array dereferencing of scalars From: rowan.collins@gmail.com (Rowan Collins) Yasuo Ohgaki wrote on 09/06/2015 11:44: > $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. PHP considers an uninitialised variable to have the value NULL, and a NULL value to be coercable to any type, so this breaks down (logically, not necessarily literally) as follows: - coerce $v to array() - instantiate $v[0] as NULL - coerce $v[0] to array() - instantiate $v[0][1] as NULL - and so on... Raising a notice whenever the type is coerced would be inconsistent with other coercions (e.g. $foo = null; echo $foo + 1;). Raising a notice whenever the coerced array is actually accessed would result in a notice for every dimension, which would be very noisy. Ideally, it would give a single notice, as in the below, but I'm not sure how that would be implemented: $v = array(); var_dump($v[0][1][2][3][4][5][6][7][8][9]); // Notice: Undefined index: 0 // NULL Note that this is all rather different from the original case, which was about values which *cannot be coerced to array*. Regards, -- Rowan Collins [IMSoP]