Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53417 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5941 invoked from network); 20 Jun 2011 15:42:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jun 2011 15:42:18 -0000 Authentication-Results: pb1.pair.com header.from=robert@xarg.org; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=robert@xarg.org; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain xarg.org from 209.85.220.170 cause and error) X-PHP-List-Original-Sender: robert@xarg.org X-Host-Fingerprint: 209.85.220.170 mail-vx0-f170.google.com Received: from [209.85.220.170] ([209.85.220.170:56598] helo=mail-vx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5D/07-34681-85A6FFD4 for ; Mon, 20 Jun 2011 11:42:17 -0400 Received: by vxi39 with SMTP id 39so1040398vxi.29 for ; Mon, 20 Jun 2011 08:42:14 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.89.110 with SMTP id bn14mr2913716vdb.206.1308584533837; Mon, 20 Jun 2011 08:42:13 -0700 (PDT) Received: by 10.220.45.196 with HTTP; Mon, 20 Jun 2011 08:42:13 -0700 (PDT) X-Originating-IP: [92.225.216.141] In-Reply-To: <4DFF661F.8020105@seld.be> References: <4DFF661F.8020105@seld.be> Date: Mon, 20 Jun 2011 17:42:13 +0200 Message-ID: To: Jordi Boggiano Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=20cf307d066e4c46c304a62694ac Subject: Re: [PHP-DEV] Negative string offsets From: robert@xarg.org (Robert Eisele) --20cf307d066e4c46c304a62694ac Content-Type: text/plain; charset=ISO-8859-1 I would push this out in two steps. First: Negative string offset and later range/slice support for objects and strings. Objects would need a new magic method, e.g. "__slice()",strings need a substr() like interface. I think both are accessed the same way, but way are different. The slice support is furthermore much more comprehensive and needs more testing and so on. BTW: I can dimly remember that {} vs [] was already concluded in favor of [] for string access. Robert 2011/6/20 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 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --20cf307d066e4c46c304a62694ac--