rfc:strncmpnegativelen

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:strncmpnegativelen [2011/07/28 05:09] laruencerfc:strncmpnegativelen [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 3: Line 3:
   * Date: 2011-07-28   * Date: 2011-07-28
   * Author: Xinchen Hui <laruence@php.net>   * Author: Xinchen Hui <laruence@php.net>
-  * Status: Under Discussion+  * Status: Withdrawn
   * First Published at: http://wiki.php.net/rfc/strncmpnegativelen/   * First Published at: http://wiki.php.net/rfc/strncmpnegativelen/
  
Line 22: Line 22:
 </code> </code>
  
-but we know substr supports a negative length as its parameter:+We need to write some codes like following one to make it works as expect
 <code php> <code php>
 <?php <?php
-   echo substr("test", 0, -1);+   if (strncmp(substr("prefix_num", -3, 3), "num", 3) === 0) { 
 +        echo "they have same suffix\n"; 
 +   } 
 +?> 
 </code> </code>
  
 ===== Proposal ===== ===== Proposal =====
- +base on feature request: https://bugs.php.net/bug.php?id=36944 , I wrote a patch to make strn(case)cmp supporting negative length,
-I wrote a patch to make strn(case)cmp supporting negative length,+
  
 after patched, following script: after patched, following script:
Line 43: Line 45:
 will work as expect. will work as expect.
  
-and if the abs of the negative length is greater than any strlen of the first two parameters,  strn(case)cmp will works as similar as the same situation with positive length:+and 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:
  
 <code php> <code php>
 <?php <?php
-  var_dump(strncmp("prefix_num", "num", -10)); +var_dump(strncmp("prefix_num", "num", -10)); 
-  //outpu: int(7)+var_dump(strncmp("mun_xiferp", "mun", 10)); 
 +/** output: 
 +int(7) 
 +int(7) 
 +*/
 ?>  ?> 
 </code> </code>
  
-===== Patchs ===== +===== BC Breaks ===== 
-   * http://www.laruence.com/php-dev/php-5-3-strncmp-supprting-negative-length.diff+   * Any strncmp call with a computed length which may end up being negative will now potentially return a match where it wouldn't before. 
 +===== Patches ===== 
 +   * http://www.laruence.com/php-dev/php-5.4-trunk-strncmp-supproting-negative-len.patch
 ===== Tests ===== ===== Tests =====
    * http://www.laruence.com/php-dev/strncmpnegativelen.phpt    * http://www.laruence.com/php-dev/strncmpnegativelen.phpt
 +===== Vote =====
 +<doodle 
 +title="Do you want this feature in PHP 5.4" auth="laruence" voteType="single" closed="yes">
 +   * yes
 +   * no
 +</doodle>
 +
 ===== Changelog ===== ===== Changelog =====
   * 2011-07-28 Xinchen Hui: Initial RFC creation   * 2011-07-28 Xinchen Hui: Initial RFC creation
 +  * 2011-07-28 Xinchen Hui: Updated patch to avoid making binary API changed
 +  * 2011-08-01 Xinchen Hui: Start voting
 +  * 2011-08-08 Xinchen Hui: Edited phpt
 +  * 2011-08-13 Xinchen Hui: Stop voting
 +  * 2011-08-14 Xinchen Hui: Open voting again, since there comes some new objections
 +  * 2011-12-13 Xinchen Hui: Won't apply now
rfc/strncmpnegativelen.1311829755.txt.gz · Last modified: 2017/09/22 13:28 (external edit)