Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60736 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 8709 invoked from network); 4 Jun 2012 19:09:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Jun 2012 19:09:05 -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.170 cause and error) X-PHP-List-Original-Sender: marc@easen.co.uk X-Host-Fingerprint: 209.85.212.170 mail-wi0-f170.google.com Received: from [209.85.212.170] ([209.85.212.170:61638] helo=mail-wi0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BE/88-01110-0D70DCF4 for ; Mon, 04 Jun 2012 15:09:05 -0400 Received: by wibhm6 with SMTP id hm6so2649173wib.5 for ; Mon, 04 Jun 2012 12:09:01 -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:cc:subject:references :in-reply-to:content-type:x-gm-message-state; bh=ZM0WWNuqz1iU5HcYdXLfthHzwmXGZyNIYC133KqEbiA=; b=igVf8omRgmUuc3MQMhTkW0Ouanu3XL0yNZHH9n8bUaWONo+Tb5EeSQuqj8JXH02DKa avVVq2a6w+b90/WeAntIRLxkSy5Ws2kbo+lpHAGWlZ0hVq3zmuLbH0GieusD60IHee7+ qv+wTOcMqSQ6h66BrWAACTx2u648+OZhQSqUQ7fz8IdxQ4/n985du4WyBQRqmU+UBtwV i2p5i3wdG4CBGLdI2KMhDztfzqlnsJ8OnroWlPJeDSgjTN7wHtO+jv8CESEgtcmpVFXw 5NbQf0ej40yyvDHWhn8rOzlD/XLAfMPKYwh5YEBo2vxmtY1E3yIu03Elb9dxvbrwyKRV so6Q== Received: by 10.216.205.5 with SMTP id i5mr11502088weo.6.1338836941076; Mon, 04 Jun 2012 12:09:01 -0700 (PDT) Received: from [192.168.1.206] (5e025a1e.bb.sky.com. [94.2.90.30]) by mx.google.com with ESMTPS id dg2sm35002973wib.4.2012.06.04.12.08.59 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 04 Jun 2012 12:09:00 -0700 (PDT) Message-ID: <4FCD07CA.7030605@easen.co.uk> Date: Mon, 04 Jun 2012 20:08:58 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 MIME-Version: 1.0 CC: "internals@lists.php.net" References: <496E551C-85F0-423E-89FA-2C5245808320@easen.co.uk> <4D309A4D.9020904@sugarcrm.com> In-Reply-To: <4D309A4D.9020904@sugarcrm.com> Content-Type: multipart/alternative; boundary="------------050403020303040000010602" X-Gm-Message-State: ALoCoQnq6GKi4v3w+ckZiT8zlGEGkhIPb0rw1w33D21vW2BEv3qNX18v3avxDsieqsda8Qiuqcu+ Subject: Re: [PHP-DEV] Support negative indexes for arrays and strings From: marc@easen.co.uk (Marc Easen) --------------050403020303040000010602 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit I have submitted a patch to support negative indexs in strings, as per the conversation adding them to arrays could possibly detract from the syntactical sugar they are indented to be. In summary: An alternative to: $var = 'abc'; echo $var[strlen($var) - 1]; Can be: $var = 'abc'; echo $var[-1]; Commit: https://github.com/Easen/php-src/commit/7016e52677f525139491467f3e76862b9a597b76 Pull request: https://github.com/php/php-src/pull/100 Thanks, On 14/01/11 18:47, Stas Malyshev wrote: > Hi! > >> I would like to open the discussion around the support of negative >> indexes, as I feel a lot of developers will benefit from this >> syntactical sugar. > > What you are looking for is implemented in array_slice(). Python has > shortcuts for this thing, like a[1:-1], but PHP doesn't. If you wanted > to RFC something here, I think the idea of $a[X:Y] with array_slice > semantics could be doable. $a[-1:1] would be your case then. --------------050403020303040000010602--