Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54604 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70559 invoked from network); 15 Aug 2011 03:18:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Aug 2011 03:18:39 -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:49449] helo=mail-vx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9B/A9-05730-C00984E4 for ; Sun, 14 Aug 2011 23:18:37 -0400 Received: by vxh24 with SMTP id 24so4001758vxh.29 for ; Sun, 14 Aug 2011 20:18:33 -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=dDpsIZfq8HPI1l9mvUM59p3LM6ZOC5i1i6cxvTrC7tA=; b=txKRb8PKvd2InI1faiplSqdtvbOTs/5U9UUpSyxdAup2UdHAQRZBBrNc/NpSiNQbAc J/FIgqHglnjPH0ctocSGYyAIQK/+Afy8z1VXUp8KVtnlxDSUH6wTfDsGuMVH6KKJekM7 YhvvHODH9PWeA0JoTihljMwsZwMuxrodOGFao= MIME-Version: 1.0 Received: by 10.52.176.166 with SMTP id cj6mr3417099vdc.155.1313378313424; Sun, 14 Aug 2011 20:18:33 -0700 (PDT) Sender: laruence@gmail.com Received: by 10.220.184.76 with HTTP; Sun, 14 Aug 2011 20:18:33 -0700 (PDT) In-Reply-To: <4E4843B0.70605@php.net> 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:18:33 +0800 X-Google-Sender-Auth: OHo0DGD-gtFuau5wwzBkBrqFuvg Message-ID: To: Rasmus Lerdorf Cc: 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: compare to use substr, 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)) { >>>> =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 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: > > =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 > > --=20 Laruence =C2=A0Xinchen Hui http://www.laruence.com/