Req #68863 [NEW]: Inconsistent return from substr()

From: Date: Tue, 20 Jan 2015 13:31:28 +0000
Subject: Req #68863 [NEW]: Inconsistent return from substr()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190073@lists.php.net to get a copy of this message
From: scott at smashcat dot org Operating system: Linux PHP version: 5.6.4 Package: Strings related Bug Type: Feature/Change Request Bug description:Inconsistent return from substr() Description: ------------ Currently the substr() function is inconsistent in its return value. Thus the value of the String object is affecting the type of object / primitive that is returned. Although the input String (shown below) is of zero length, it's still a String. So currently the returned value type needs to be checked by the calling code. To return a consistent type of value I suggest that either the last case should return an empty string, OR the substr() function should return boolean false if the input string is shorter than the required substr. Test script: --------------- substr("a",0,10); substr("a",0,0); substr("",0,10); substr("",0,0); Expected result: ---------------- substr("a",0,10) === false substr("abc",0,1) === "a" substr("",0,0) === "" substr("",0,1) === false Actual result: -------------- substr("a",0,10) == "a" substr("a",0,0) == "" substr("",0,10) == false substr("",0,0) == false -- Edit bug report at https://bugs.php.net/bug.php?id=68863&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68863&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68863&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68863&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=68863&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=68863&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=68863&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=68863&r=needscript Try newer version: https://bugs.php.net/fix.php?id=68863&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=68863&r=support Expected behavior: https://bugs.php.net/fix.php?id=68863&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=68863&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=68863&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=68863&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68863&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=68863&r=dst IIS Stability: https://bugs.php.net/fix.php?id=68863&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=68863&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=68863&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=68863&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=68863&r=mysqlcfg

« previous php.bugs (#190073) next »