Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54605 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73363 invoked from network); 15 Aug 2011 03:48:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Aug 2011 03:48:24 -0000 Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.170 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 74.125.82.170 mail-wy0-f170.google.com Received: from [74.125.82.170] ([74.125.82.170:56486] helo=mail-wy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 18/1A-05730-607984E4 for ; Sun, 14 Aug 2011 23:48:23 -0400 Received: by wyf23 with SMTP id 23so3573834wyf.29 for ; Sun, 14 Aug 2011 20:48:18 -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=/N/difsKcyOWlgt57G9nvIy5U/z78u2u/1dCot0Dj3Y=; b=Oozv1aJpMr9QEV98qWfrNM2eaTgJvX+8cmVYciTKzwCkKBsAf4vYbJpCGxQYpwLOhp rWEyK+UPjeVLATqWoPIVGcak9QV7a59pjoBQJF1JzcarWBTS/3ksAeiBbA6yFBQi2lVk E0SuzargVQZQ1jkojPhKR+phciHFJpJLSjwgo= MIME-Version: 1.0 Received: by 10.227.35.199 with SMTP id q7mr615120wbd.38.1313380098591; Sun, 14 Aug 2011 20:48:18 -0700 (PDT) Sender: tjerk.meesters@gmail.com Received: by 10.227.61.8 with HTTP; Sun, 14 Aug 2011 20:48:18 -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 11:48:18 +0800 X-Google-Sender-Auth: COU4iOW2-RSUJfdXVs4QGQpj15g Message-ID: To: Laruence Cc: Rasmus Lerdorf , Stas Malyshev , Derick Rethans , PHP Internals Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [VOTE]strn(case)cmp supporting a negative length as its third paramter From: datibbaw@php.net (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, Tjerk On Mon, Aug 15, 2011 at 11:18 AM, Laruence wrote: > Hi: > =A0 compare to use substr, =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 people >>>> >>>> And why should anybody care? 99% of people using PHP never used a libc >>>> 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)) { >>>>> =A0 =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 message >>>> 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: >> >> =A0 if (substr("prefix_num", -3) =3D=3D "num") { >> =A0 =A0 =A0 =A0echo "they have same suffix\n"; >> =A0 } >> >> >> into: >> >> =A0 if (strncmp("prefix_num", "num", -3) =3D=3D=3D 0) { >> =A0 =A0 =A0 =A0echo "they have same suffix\n"; >> =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 =A0Xinchen Hui > http://www.laruence.com/ > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --=20 -- Tjerk