From: janne dot salo at exove dot fi Operating system: CentOS 5.2 PHP version: 5.2.8 PHP Bug Type: Strings related Bug description: Unexpected substr return value when start is negative
Description: ------------ When substr is given a negative value as $start AND the absolute value of $start is greater than the length of the string, something unexpected occurs: $start seems to be considered equal to 0 in this case. The documentation states: "If string is less than or equal to start characters long, FALSE will be returned". Strict intepretation would be that if $start is negative, FALSE will never be returned since a negative start can never be greater than the length of the string. However, what you would expect (and what you get in versions older than 5.2.8) is that if the ABSOLUTE value of start is greater than the length of the string, FALSE will be returned. Reproduce code: --------------- substr("1234567", -9, 2); Expected result: ---------------- The above call returns FALSE in previous PHP versions (tested with 5.2.2 in MacOS X and 5.2.6 in Fedora 8). Actual result: -------------- '12'. (Which corresponds to call substr("1234567", 0, 2)) -- Edit bug report at http://bugs.php.net/?id=47298&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=47298&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=47298&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=47298&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=47298&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=47298&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=47298&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=47298&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=47298&r=needscript Try newer version: http://bugs.php.net/fix.php?id=47298&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=47298&r=support Expected behavior: http://bugs.php.net/fix.php?id=47298&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=47298&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=47298&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=47298&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47298&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=47298&r=dst IIS Stability: http://bugs.php.net/fix.php?id=47298&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=47298&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=47298&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=47298&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=47298&r=mysqlcfg