Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54608 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81852 invoked from network); 15 Aug 2011 05:00:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Aug 2011 05:00:38 -0000 Authentication-Results: pb1.pair.com smtp.mail=laruence@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=laruence@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.170 as permitted sender) X-PHP-List-Original-Sender: laruence@gmail.com X-Host-Fingerprint: 209.85.220.170 mail-vx0-f170.google.com Received: from [209.85.220.170] ([209.85.220.170:54795] helo=mail-vx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 44/B0-12367-4F7A84E4 for ; Mon, 15 Aug 2011 01:00:37 -0400 Received: by vxh24 with SMTP id 24so4032914vxh.29 for ; Sun, 14 Aug 2011 22:00:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=QXJky0qyDG2aqvtcNmCoDMVyo5Etc1eEgnOAwoyfwFU=; b=clTzWu+8BLNmURuNv7EzpYuO0UgHPbfpaOdPFQ0nXeyoULhLbj+TMulWhPuGJOFwfc cOOTjnnFKl6CL3V1Y0QE0GgTMOEMbf/E0mJVnw43rApJfEpFzdQWwBCQyn5WvYldCI5E lPwL6VgtQ3tjZKdfNU7ATeb7qfc2s6bl5Uy94= MIME-Version: 1.0 Received: by 10.52.182.6 with SMTP id ea6mr3415979vdc.222.1313384434210; Sun, 14 Aug 2011 22:00:34 -0700 (PDT) Sender: laruence@gmail.com Received: by 10.220.184.76 with HTTP; Sun, 14 Aug 2011 22:00:34 -0700 (PDT) In-Reply-To: References: <4E48121A.3090007@sugarcrm.com> <4E48134E.4030708@sugarcrm.com> <4E481695.6040900@php.net> <4E483804.7070009@sugarcrm.com> <4E484037.2080107@php.net> <4E4843B0.70605@php.net> Date: Mon, 15 Aug 2011 13:00:34 +0800 X-Google-Sender-Auth: VU-QcfZ1nGIJY2y9AYOQ2ES6-7s Message-ID: To: Tjerk Anne Meesters Cc: Rasmus Lerdorf , Stas Malyshev , Derick Rethans , PHP Internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [VOTE]strn(case)cmp supporting a negative length as its third paramter From: laruence@php.net (Laruence) Hi Tjerk: yes, substr_compare can do it, and it also supports negative length argument too. but I am proposal to improve strn(case)cmp, so they are not conflict . = :) thanks 2011/8/15 Tjerk Anne Meesters : > Hi, > > Doesn't substr_compare() accomplish the same thing since 5.1.0? > > The only thing I couldn't figure out is how to make it case > insensitive without specifying an explicit value to $length > > > Best, > =C2=A0Tjerk > > On Mon, Aug 15, 2011 at 11:18 AM, Laruence wrote: >> Hi: >> =C2=A0 compare to use substr, =C2=A0 strncmp supporting negative lenght = can >> save a temp variable. >> >> thanks >> >> 2011/8/15 Rasmus Lerdorf : >>> On 08/14/2011 02:37 PM, Rasmus Lerdorf wrote: >>>> On 08/14/2011 02:03 PM, Stas Malyshev wrote: >>>>> Hi! >>>>> >>>>> On 8/14/11 11:40 AM, Rasmus Lerdorf wrote: >>>>>> My main issue with changing strncmp/strncasecmp is that these are >>>>>> currently exact mappings of the underlying libc functions. For peopl= e >>>>> >>>>> And why should anybody care? 99% of people using PHP never used a lib= c >>>>> function and can hardly tell libc from gcc. If we can extend this >>>>> function with useful functionality, nobody cares about what libc does= . >>>>> >>>>>> For example, I could imagine people writing code along these lines: >>>>>> >>>>>> $len =3D strlen($user_data) - strlen($suffix); >>>>>> if(!strncmp($user_data, $string, $len)) { >>>>>> =C2=A0 =C2=A0 // do something >>>>>> } >>>>> >>>>> Warning doesn't fix the bug - and unless you're in 0.0001% of the >>>>> population that actually reads the logs daily and checks every messag= e >>>>> there it would be little to help you. We should have more useful >>>>> functions, not more warnings. Warning won't make this code to work. >>>> >>>> I agree, however this change would potentially change the return value >>>> of the function. Before it would warn and not match. Even if you never >>>> saw the warning, at least length -1 would not give you a match. Now if >>>> the user data happens to end with the right character we now have a >>>> string match which is not at all what the code was written to do. >>> >>> Put more succinctly. Subtle BC breaks like this worry me. Any strncmp() >>> call with a computed length where that length may in some cases go >>> negative will now potentially return a match where it wouldn't before. >>> This would be very hard to track down. And the reason for introducing >>> this subtle BC break is so that you can rewrite: >>> >>> =C2=A0 if (substr("prefix_num", -3) =3D=3D "num") { >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0echo "they have same suffix\n"; >>> =C2=A0 } >>> >>> >>> into: >>> >>> =C2=A0 if (strncmp("prefix_num", "num", -3) =3D=3D=3D 0) { >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0echo "they have same suffix\n"; >>> =C2=A0 } >>> >>> That doesn't seem like a big win to me. >>> >>> -Rasmus >>> >>> -- >>> PHP Internals - PHP Runtime Development Mailing List >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >>> >> >> >> >> -- >> Laruence =C2=A0Xinchen Hui >> http://www.laruence.com/ >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > > > > -- > -- > Tjerk > --=20 Laruence =C2=A0Xinchen Hui http://www.laruence.com/