Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60795 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 25012 invoked from network); 11 Jun 2012 20:25:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jun 2012 20:25:54 -0000 Authentication-Results: pb1.pair.com header.from=marc@easen.co.uk; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=marc@easen.co.uk; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain easen.co.uk from 209.85.212.176 cause and error) X-PHP-List-Original-Sender: marc@easen.co.uk X-Host-Fingerprint: 209.85.212.176 mail-wi0-f176.google.com Received: from [209.85.212.176] ([209.85.212.176:65332] helo=mail-wi0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5D/16-18025-15456DF4 for ; Mon, 11 Jun 2012 16:25:54 -0400 Received: by wibhn14 with SMTP id hn14so2757725wib.11 for ; Mon, 11 Jun 2012 13:25:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=XLte9uBfzYFbh7MqUjHCG8MMhRr8U5mS/hD0E0gK+0Y=; b=lShjlX19MfqMruJ00Nnxo8oW5DHFTOXUEF+fLu1DhI4ItxtdsQtFZzA7J3Flq1eHuo WGdPaG8JEyvhft7eHCn0cJyCK2TYzoBcM/qFEWPo1+Gedd8MXlCGCAfyzhQzTQBaXAN0 GlBC0pSCdyy4ugNtinUVq3zRe/PAGTSPrwt2ow8F8yOV8xdjxh/vA5mta/qw39P0w5KD vO/OIewx2cokD62JJQCdat1EhAworKH+lkiTHEI6O0G1ecjUEYtVKeTLymL1djOCedxy EKioWmK4pQEqjhVCsBSCN0W30eWNizBAQBuMoEvA9IeRkPAzSTf0AQSpbawo/6f9R0C9 2ecA== Received: by 10.216.138.217 with SMTP id a67mr7510512wej.71.1339446348664; Mon, 11 Jun 2012 13:25:48 -0700 (PDT) Received: from [192.168.1.206] (5e025a1e.bb.sky.com. [94.2.90.30]) by mx.google.com with ESMTPS id gb9sm666328wib.8.2012.06.11.13.25.47 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 11 Jun 2012 13:25:47 -0700 (PDT) Message-ID: <4FD6544A.1020602@easen.co.uk> Date: Mon, 11 Jun 2012 21:25:46 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120420 Thunderbird/12.0 MIME-Version: 1.0 To: internals@lists.php.net 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> <833ec4f42697843267a741e3f50b0bd0.squirrel@www.l-i-e.com> In-Reply-To: <833ec4f42697843267a741e3f50b0bd0.squirrel@www.l-i-e.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQkj5rtprY84+XzqO08ZLXBgClMcPzxkrPVffMp3AgxJenkkA2gRrj2lDO8XdlRXvr1ZooFx Subject: Re: [PHP-DEV] Support negative indexes for arrays and strings From: marc@easen.co.uk (Marc Easen) On 11/06/12 20:28, Richard Lynch wrote: > On Mon, June 11, 2012 2:13 pm, Stas Malyshev wrote: >>> 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. > $n = some_incredibly_long_and_complex_computation(); > //and, for real fun, sometimes it returns positive, and sometimes > negative. > > $s = $var[$n]; If $n is a negative value, an E_NOTICE will be triggered. To not do > if ($n< 0){ > //whatever > } > else{ > //something entirely different > } Prior to your string offset can be looked at being bad practice.