Re: [RFC]strn(case)cmp supporting negative length as third parameter

From: Date: Fri, 29 Jul 2011 01:08:32 +0000
Subject: Re: [RFC]strn(case)cmp supporting negative length as third parameter
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-54242@lists.php.net to get a copy of this message
Hi: first of all, yes , you are right about the reverse order thing: and then, they are not equal: <?php echo "strncmp:\n"; var_dump(strncmp("laruence", "nce", -10)); var_dump(strncmp("ecneural", "ecn", 10)); var_dump(strncmp("ecneural", "ecn", 3)); var_dump(strncmp("laruence", "nce", -3)); ?> will output: strncmp: int(5) int(5) int(0) int(0) thanks 2011/7/29 Ángel González <keisial@gmail.com>: > Laruence wrote: >> >> Hi: >> >>   strn(case)cmp dosen't  support a negative length as its third >> paramter,  while substr dose. > >>  here is the rfc: >> https://wiki.php.net/rfc/strncmpnegativelen >> >>  any question? plz worte me back. >> >>  thanks > > What do you exactly mean by "in the reverse order" in >> >> if the abs of the negative length is greater than any strlen of the first >> two parameters, then strn(case)cmp will work as strncmp in the reverse order >> with the abs value: > > Looking at >> >> var_dump  <http://www.php.net/var_dump>(strncmp >> >>  <http://www.php.net/strncmp>("prefix_num", >>  "num",  -10)); >>   //outpu: int(7) > > it seems to mean that it would be equivalent to >> >> var_dump(strncmp("mun_xiferp", "mun", 10)); > > However, if I'm reading the patch correctly, it would > be taking the smaller string. Ie. it would be equivalent > to > >> var_dump  <http://www.php.net/var_dump>(strncmp >> >>  <http://www.php.net/strncmp>("prefix_num", >>  "num",  -3)); > > Seems an implementation bug. > > -- Laruence  Xinchen Hui http://www.laruence.com/

« previous php.internals (#54242) next »