Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54612 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 93398 invoked from network); 15 Aug 2011 07:05:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Aug 2011 07:05:08 -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.212.42 as permitted sender) X-PHP-List-Original-Sender: laruence@gmail.com X-Host-Fingerprint: 209.85.212.42 mail-vw0-f42.google.com Received: from [209.85.212.42] ([209.85.212.42:33366] helo=mail-vw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0B/62-12367-225C84E4 for ; Mon, 15 Aug 2011 03:05:07 -0400 Received: by vwl1 with SMTP id 1so4204801vwl.29 for ; Mon, 15 Aug 2011 00:05:04 -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=vFUAIZLhyy147JCRsaXro6lohnkUeZbA3KY8FMjITAw=; b=bk/0vV3W456rBCBkxra7uIFC5zYyE3O07ejBRedsI8bKeI8guhjbPPVEW/WVMX0U7f i2CsJQ52fu0MNrnA/F2Q6NjV0hAo+UP7XvpbYL5KSLWuzY4TeVMvO7+IN7uVwA4ZO7MN jfg1hn3WLdrpdRKl9wC/cm72v9JTwADxDZ9mw= MIME-Version: 1.0 Received: by 10.52.176.166 with SMTP id cj6mr3555381vdc.155.1313391903885; Mon, 15 Aug 2011 00:05:03 -0700 (PDT) Sender: laruence@gmail.com Received: by 10.220.184.76 with HTTP; Mon, 15 Aug 2011 00:05:03 -0700 (PDT) In-Reply-To: <4E48A081.2080300@googlemail.com> 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> <4E48A081.2080300@googlemail.com> Date: Mon, 15 Aug 2011 15:05:03 +0800 X-Google-Sender-Auth: RhsM2UHEaZNG669mM2DQhyZUHJw Message-ID: To: sebastian.krebs.berlin@googlemail.com Cc: internals@lists.php.net 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: I think we are not talking about how to accomplish a function, we are talking about how to do it better and, in fact, I think strrev is need more cpu time and alloc space, although they are very tiny :) thanks 2011/8/15 Sebastian Krebs : > > > Am 14.08.2011 23:52, schrieb 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 =C2=A0if (substr("prefix_num", -3) =3D=3D "num") { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 echo "they have same suffix\n"; >> =C2=A0 =C2=A0} >> >> >> into: >> >> =C2=A0 =C2=A0if (strncmp("prefix_num", "num", -3) =3D=3D=3D 0) { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 echo "they have same suffix\n"; >> =C2=A0 =C2=A0} >> >> That doesn't seem like a big win to me. > > Or just > > =C2=A0 =C2=A0if (strncmp(strrev('prefix_num'), 'mun', 3) =3D=3D=3D 0) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0// do something > =C2=A0 =C2=A0} > > >> >> -Rasmus >> > > > Regards, > Sebastian > > -- > 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/