Req #62922 [Com]: Truncating entire string should result in string

From: Date: Fri, 24 Aug 2012 14:21:21 +0000
Subject: Req #62922 [Com]: Truncating entire string should result in string
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-172877@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=62922&edit=1 ID: 62922 Comment by: dagguh at gmail dot com Reported by: dagguh at gmail dot com Summary: Truncating entire string should result in string Status: Open Type: Feature/Change Request Package: Strings related PHP Version: 5.3.16 Block user comment: N Private report: N New Comment: Sheer logic. What remains from a 4-character string after cutting 4 characters? An empty string. In practice it would allow for a cleaner code, like: --------- public static function endsWith($string, $suffix) { $suffixLength = strlen($suffix); return $suffix === substr($string, -$suffixLength); } -------- Method endsWith returns true for: endsWith("kebab", "ebab"); endsWith("kebab", "bab"); endsWith("kebab", "ab"); endsWith("kebab", "b"); but it returns false for endsWith("kebab", "kebab"); Previous Comments: ------------------------------------------------------------------------ [2012-08-24 12:28:43] laruence@php.net what can we gain from changing this? except the bc break? ------------------------------------------------------------------------ [2012-08-24 10:16:57] dagguh at gmail dot com Description: ------------ --- From manual page: http://www.php.net/function.substr#refsect1-function.substr- description --- Truncating an entire string should result in a string. When $start is equal to strlen($string), an empty string should be returned instead of FALSE. Test script: --------------- var_dump(substr("", 0)); var_dump(substr("a", 1)); var_dump(substr("ab", 2)); Expected result: ---------------- string(0) "" string(0) "" string(0) "" Actual result: -------------- bool(false) bool(false) bool(false) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=62922&edit=1

« previous php.bugs (#172877) next »