Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54598 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 38659 invoked from network); 14 Aug 2011 21:38:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Aug 2011 21:38:05 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lerdorf.com from 209.85.210.172 cause and error) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 209.85.210.172 mail-iy0-f172.google.com Received: from [209.85.210.172] ([209.85.210.172:64289] helo=mail-iy0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 57/55-05730-B30484E4 for ; Sun, 14 Aug 2011 17:38:04 -0400 Received: by iye7 with SMTP id 7so7256235iye.31 for ; Sun, 14 Aug 2011 14:38:01 -0700 (PDT) Received: by 10.42.74.202 with SMTP id x10mr3196967icj.142.1313357881320; Sun, 14 Aug 2011 14:38:01 -0700 (PDT) Received: from [192.168.200.5] (c-50-131-46-20.hsd1.ca.comcast.net [50.131.46.20]) by mx.google.com with ESMTPS id q13sm3408257ibi.43.2011.08.14.14.37.59 (version=SSLv3 cipher=OTHER); Sun, 14 Aug 2011 14:38:00 -0700 (PDT) Sender: Rasmus Lerdorf Message-ID: <4E484037.2080107@php.net> Date: Sun, 14 Aug 2011 14:37:59 -0700 Organization: PHP Development Team User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:5.0) Gecko/20110627 Thunderbird/5.0 MIME-Version: 1.0 To: Stas Malyshev CC: Derick Rethans , PHP Internals References: <4E48121A.3090007@sugarcrm.com> <4E48134E.4030708@sugarcrm.com> <4E481695.6040900@php.net> <4E483804.7070009@sugarcrm.com> In-Reply-To: <4E483804.7070009@sugarcrm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [VOTE]strn(case)cmp supporting a negative length as its third paramter From: rasmus@php.net (Rasmus Lerdorf) 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 = strlen($user_data) - strlen($suffix); >> if(!strncmp($user_data, $string, $len)) { >> // 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. -Rasmus