====== RFC: strn(case)cmp supporting a negative length as its third paramter ====== * Version: 1.0 * Date: 2011-07-28 * Author: Xinchen Hui * Status: Withdrawn * First Published at: http://wiki.php.net/rfc/strncmpnegativelen/ ===== Introduction ===== strncmp doesn't supporting negative length: running the above script in PHP 5.3.6 will result: warning: Length must be greater than or equal to 0 in /tmp/1.php We need to write some codes like following one to make it works as expect: ===== 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, after patched, following script: will work as expect. 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: ===== BC Breaks ===== * 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 ===== * http://www.laruence.com/php-dev/strncmpnegativelen.phpt ===== Vote ===== * yes * no ===== Changelog ===== * 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