Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53411 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94137 invoked from network); 20 Jun 2011 15:24:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jun 2011 15:24:23 -0000 Authentication-Results: pb1.pair.com header.from=j.boggiano@seld.be; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=j.boggiano@seld.be; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain seld.be designates 74.125.82.170 as permitted sender) X-PHP-List-Original-Sender: j.boggiano@seld.be X-Host-Fingerprint: 74.125.82.170 mail-wy0-f170.google.com Received: from [74.125.82.170] ([74.125.82.170:33218] helo=mail-wy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E4/94-34681-5266FFD4 for ; Mon, 20 Jun 2011 11:24:23 -0400 Received: by wyf22 with SMTP id 22so1725025wyf.29 for ; Mon, 20 Jun 2011 08:24:18 -0700 (PDT) Received: by 10.216.81.8 with SMTP id l8mr3527278wee.72.1308583457871; Mon, 20 Jun 2011 08:24:17 -0700 (PDT) Received: from [192.168.1.63] (40-34.60-188.cust.bluewin.ch [188.60.34.40]) by mx.google.com with ESMTPS id u64sm2960868weq.4.2011.06.20.08.24.16 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 20 Jun 2011 08:24:17 -0700 (PDT) Message-ID: <4DFF661F.8020105@seld.be> Date: Mon, 20 Jun 2011 17:24:15 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101027 Lightning/1.0b2 Thunderbird/3.1.6 MIME-Version: 1.0 To: internals@lists.php.net References: In-Reply-To: X-Enigmail-Version: 1.1.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Negative string offsets From: j.boggiano@seld.be (Jordi Boggiano) On 20.06.2011 14:02, Robert Eisele wrote: > Negative string offsets is a wish and also an implementation of my running > PHP version for long. It operates in the same fashion like substr() with > negative offsets, but avoids the function call and is much smarter if one > single character has to be extracted: > > $str = "Hallo"; > > $str[0] == "H" > $str[-1] == "o"; > > If -6 is used as offset, the old warning is displayed because it's the first > undefined negative offset. > > The same thing for setting: > > $str[-1] = '0'; > $str[-4] = "4"; > > will result in "H4ll0" > > Would be glad to see this in 5.4 While this in itself is a good thing, I'd prefer to wait some more and get a well thought-through, full fledged solution supporting ranges i.e. $str[-1:2] or $str[-1,2]. I believe there were talks of such syntax a few years ago, maybe using {} instead of []. I mean, right now both [] and {} seem to work equally on strings and arrays, but changing {} to make it behave more like substr/array_slice might be a viable BC break (for the negative numbers that might exist in arrays that is). Cheers -- Jordi Boggiano @seldaek - http://nelm.io/jordi