Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60793 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19415 invoked from network); 11 Jun 2012 19:29:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jun 2012 19:29:21 -0000 Authentication-Results: pb1.pair.com header.from=ww.galen@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ww.galen@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.176 as permitted sender) X-PHP-List-Original-Sender: ww.galen@gmail.com X-Host-Fingerprint: 209.85.212.176 mail-wi0-f176.google.com Received: from [209.85.212.176] ([209.85.212.176:59005] helo=mail-wi0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 40/25-18025-01746DF4 for ; Mon, 11 Jun 2012 15:29:21 -0400 Received: by wibhn14 with SMTP id hn14so2713652wib.11 for ; Mon, 11 Jun 2012 12:29:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=IIhVNolreUlH5ujMCp3F5YtINpFG/EfrpT/ZA/AphAE=; b=GBth+fjY5fhuo6qFKyzRSN8PG8WbrsPoddGSyhzWwgBEQvswBX2g7QFLZN8oEZlBij G/pzEhC/6mQQqNhpuBj7FeZvoQFbJkVuNGwhtI78HS6rHMtTeSQsIQRUTg72s75oryvN ZoM81wYjop7NOU8TadBiUSC5Jn8nDMqWGmcBfo+iZMhPQA45mg/IWIzX/yqaR6314sNn XmuiNRDPMmSnht1PQN8RyIZDIjC5lpRuiXKkfF6K7h0c3LazI2u+CFi+TgAjcZjqhxHb ML5siNG9UU/t1wPuTgmREcJuUq7yGM/YKmEVTZaG7crLZm3zHmH3+mByAr8+qLia/rBp 3YvA== Received: by 10.216.194.137 with SMTP id m9mr6977280wen.66.1339442957983; Mon, 11 Jun 2012 12:29:17 -0700 (PDT) MIME-Version: 1.0 Received: by 10.194.61.37 with HTTP; Mon, 11 Jun 2012 12:28:37 -0700 (PDT) In-Reply-To: <4FD6436B.1080200@sugarcrm.com> References: <496E551C-85F0-423E-89FA-2C5245808320@easen.co.uk> <4D309A4D.9020904@sugarcrm.com> <4FCD07CA.7030605@easen.co.uk> <131ff485e2f37a4388919f1c61fd4816.squirrel@www.l-i-e.com> <4FD6436B.1080200@sugarcrm.com> Date: Mon, 11 Jun 2012 12:28:37 -0700 Message-ID: To: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=0016e6d7ef9bb51ecb04c2375db7 Subject: Re: [PHP-DEV] Support negative indexes for arrays and strings From: ww.galen@gmail.com (Galen Wright-Watson) --0016e6d7ef9bb51ecb04c2375db7 Content-Type: text/plain; charset=ISO-8859-1 On Mon, Jun 11, 2012 at 12:13 PM, Stas Malyshev wrote: > Hi! > > >> Can be: > >> $var = 'abc'; > >> echo $var[-1]; > > > > This seems simple enough for a hard-coded -1, but... > > > > Would $var[-2] be strlen($var) - 2 and so on? > > The main question is what happens with "foo"[-4] or ['x'][-2]. > The same thing that currently happens for: $f='foo'; echo $f[strlen($f)-4]; $a=['x']; $a[count($a)-2]; which appears to be notices: Notice: Uninitialized string offset: -1 in - on line 2 > Notice: Undefined offset: -1 in - on line 3 > And then one would expect some rather complex logic to compute -N for > > $var[-N] > > I don't see much of complex logic here, but $a[2] = 'a' would create a > new array element if it does not exist, while $a[-2] can't. Not a big > issue, but somewhat inconsistent I guess. > Negative indices are currently valid for arrays. If anyone makes use of negative indices, this could break their script. Personally, I'd rather have Marc Easen's behavior. --0016e6d7ef9bb51ecb04c2375db7--