length arg of byteSubstr is now optional

This commit is contained in:
Carsten Brandt
2014-07-30 13:27:30 +02:00
parent cde71f4318
commit 7af92173b1
3 changed files with 33 additions and 3 deletions

View File

@@ -82,6 +82,7 @@ Yii Framework 2 Change Log
- Bug: URL encoding for the route parameter added to `\yii\web\UrlManager` (klimov-paul)
- Bug: Fixed the bug that requesting protected or private action methods would cause 500 error instead of 404 (qiangxue)
- Bug: Fixed Object of class Imagick could not be converted to string in CaptchaAction (eXprojects, cebe)
- Bug: Fixed wrong behavior of `StringHelper::byteSubstr()` in some edge cases (cebe)
- Enh #87: Helper `yii\helpers\Security` converted into application component, cryptographic strength improved (klimov-paul)
- Enh #422: Added Support for BIT(M) data type default values in Schema (cebe)
- Enh #1160: Added $strict parameter to Inflector::camel2id() to handle consecutive uppercase chars (schmunk)

View File

@@ -34,13 +34,14 @@ class BaseStringHelper
* This method ensures the string is treated as a byte array by using `mb_substr()`.
* @param string $string the input string. Must be one character or longer.
* @param integer $start the starting position
* @param integer $length the desired portion length
* @param integer $length the desired portion length. If not specified or `null`, there will be
* no limit on length i.e. the output will be until the end of the string.
* @return string the extracted part of string, or FALSE on failure or an empty string.
* @see http://www.php.net/manual/en/function.substr.php
*/
public static function byteSubstr($string, $start, $length)
public static function byteSubstr($string, $start, $length = null)
{
return mb_substr($string, $start, $length ?: mb_strlen($string, '8bit'), '8bit');
return mb_substr($string, $start, $length === null ? mb_strlen($string, '8bit') : $length, '8bit');
}
/**