Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:73725 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73276 invoked from network); 17 Apr 2014 16:05:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Apr 2014 16:05:44 -0000 Authentication-Results: pb1.pair.com smtp.mail=sean@seancoates.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=sean@seancoates.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain seancoates.com from 208.72.237.35 cause and error) X-PHP-List-Original-Sender: sean@seancoates.com X-Host-Fingerprint: 208.72.237.35 b-pb-sasl-quonix.pobox.com Received: from [208.72.237.35] ([208.72.237.35:55098] helo=smtp.pobox.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 42/45-39661-6DBFF435 for ; Thu, 17 Apr 2014 12:05:43 -0400 Received: from smtp.pobox.com (unknown [127.0.0.1]) by b-sasl-quonix.pobox.com (Postfix) with ESMTP id 30F5C7B9AC; Thu, 17 Apr 2014 12:05:40 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=content-type :mime-version:subject:from:in-reply-to:date:cc:message-id :references:to; s=sasl; bh=iqd+d7iF6VzZilqtxzkKYmFMYo4=; b=ZVZHa gU4OhJSEM7QedbsDui+Hsf9ikxp4Bld6Jb2dEUHfi8rS3rwoxvdaqxLjdFtR2AaZ olHaFWuMMbF3uxqqN7//ipMQMCRdAcwMrmSEq+zkcSNZ76JqpYtv1cyu9cvKIuXC I0NIAowHPtYPOtIX0ej+sTixDv1JSHiWym59lA= Received: from b-pb-sasl-quonix.pobox.com (unknown [127.0.0.1]) by b-sasl-quonix.pobox.com (Postfix) with ESMTP id 1CD747B9AB; Thu, 17 Apr 2014 12:05:40 -0400 (EDT) Received: from [192.168.145.200] (unknown [96.22.16.115]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by b-sasl-quonix.pobox.com (Postfix) with ESMTPSA id A73D87B9AA; Thu, 17 Apr 2014 12:05:38 -0400 (EDT) Content-Type: multipart/alternative; boundary="Apple-Mail=_F00F8511-8145-4272-8BAA-7EAFD32EAEF2" Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\)) In-Reply-To: <534FF26E.6070602@lerdorf.com> Date: Thu, 17 Apr 2014 11:41:00 -0400 Cc: "internals@lists.php.net Internals" Message-ID: <838439B2-6179-4748-9EC1-525BF8D37072@seancoates.com> References: <1397744009.2829.3212.camel@guybrush> <1397747255.2829.3225.camel@guybrush> <534FF26E.6070602@lerdorf.com> To: Rasmus Lerdorf X-Mailer: Apple Mail (2.1510) X-Pobox-Relay-ID: 1E3543DC-C64A-11E3-AA7A-0731802839F8-96568589!b-pb-sasl-quonix.pobox.com Subject: Re: [PHP-DEV] Negative string offsets From: sean@seancoates.com (Sean Coates) --Apple-Mail=_F00F8511-8145-4272-8BAA-7EAFD32EAEF2 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=iso-8859-1 > Yeah, it wouldn't make any sense unless it supported ranges. Something = like: >=20 > if($filename[-4,4] =3D=3D=3D '.ext') ... >=20 > although, I don't see how that is better than: >=20 > if(substr($filename,-4) =3D=3D=3D '.ext') ... >=20 > The latter is much clearer. FWIW, I realize they're different systems (for one thing, strings are = not objects, here), but I think it's worth considering that this is = really useful in Python, and the ranges work a bit differently (the = second value is absolute, not relative, and both values are optional): >>> "foo.bar.baz"[-4] '.' >>> "foo.bar.baz"[-4:] '.baz' >>> "foo.bar.baz"[-4:3] '' >>> "foo.bar.baz"[-4:] '.baz' >>> "foo.bar.baz"[-4:-1] '.ba' >>> "foo.bar.baz"[-4:11] '.baz' >>> "foo.bar.baz"[-4:10] '.ba' >>> "foo.bar.baz"[:-4] 'foo.bar' >>> "foo.bar.baz"[4:7] 'bar' >>> "foo.bar.baz"[:] 'foo.bar.baz' Similarly, `:` as a range operator (here) makes it clear at a glance = that it's not an array: `[4:7]` vs `[4,7]`. S --Apple-Mail=_F00F8511-8145-4272-8BAA-7EAFD32EAEF2--