Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54591 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18724 invoked from network); 14 Aug 2011 18:40:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Aug 2011 18:40:28 -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:58938] helo=mail-iy0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B8/72-05730-A96184E4 for ; Sun, 14 Aug 2011 14:40:26 -0400 Received: by iye7 with SMTP id 7so6998698iye.31 for ; Sun, 14 Aug 2011 11:40:23 -0700 (PDT) Received: by 10.42.147.194 with SMTP id o2mr3372174icv.461.1313347223328; Sun, 14 Aug 2011 11:40:23 -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 eq6sm3088293ibb.12.2011.08.14.11.40.22 (version=SSLv3 cipher=OTHER); Sun, 14 Aug 2011 11:40:22 -0700 (PDT) Sender: Rasmus Lerdorf Message-ID: <4E481695.6040900@php.net> Date: Sun, 14 Aug 2011 11:40:21 -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> In-Reply-To: <4E48134E.4030708@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 11:26 AM, Stas Malyshev wrote: > Hi! > >>> Maybe, but I would classify *that* as a bug as it makes no sense at all. > > Thinking more about it, something like: > > if(strncasecmp($filename, ".php", -4) === 0) { > /* got php file! */ > } > > seems to me just fine and better than doing the same with substr. I > would definitely be against the warning in this case. My main issue with changing strncmp/strncasecmp is that these are currently exact mappings of the underlying libc functions. For people familiar with the underlying functionality having a negative length parameter do something would be confusing and in some cases could mask bugs. 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 } That is, check to see if the part of a $user_data without a given suffix matches $string. That should obviously also have a check to make sure that $user_data is at least as long as $suffix, but if they forget this check then they get a nice warning telling them that "Length must be greater than or equal to 0." If we change this to now make negative lengths work, code like this will do extremely unexpected things. -Rasmus