#40531 [NEW]: mb_substr optional parameters
| From: | emwebdev at hotmail dot com | Date: | Sun, 18 Feb 2007 08:15:58 +0000 |
| Subject: | #40531 [NEW]: mb_substr optional parameters | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-109070@lists.php.net to get a copy of this message | ||
From: emwebdev at hotmail dot com
Operating system: Windows XP
PHP version: 5.2.1
PHP Bug Type: mbstring related
Bug description: mb_substr optional parameters
Description:
------------
Hi there
I'm not sure if the following is intended functionality or a bug, but I've
tried many forums etc. and been unable to get an answer.
When you use mb_substr() and omit the third argument (length), the
function returns all characters from the start index to the end of the
string.
This is fine unless you want to specify the character encoding explicitly
as the fourth argument. This forces you to supply the length argument
also.
It would seem logical that passing null for the length argument would make
mb_substr() behave the same as if it had been omitted, but this is not the
case.
Passing null as the length argument to mb_substr() (or substr() itself for
that matter) will produce an empty string every time.
This means that to achieve the same functionality displayed when the
length argument is omitted, you have to calculate the remaining string
length yourself which is no doubt much less efficient.
Thanks for your time,
Erin
Reproduce code:
---------------
var_dump(substr('foobar', 3));
var_dump(substr('foobar', 3, null));
Expected result:
----------------
'bar' (length=3)
'bar' (length=3)
Actual result:
--------------
'bar' (length=3)
'' (length=0)
--
Edit bug report at http://bugs.php.net/?id=40531&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=40531&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=40531&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=40531&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=40531&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=40531&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=40531&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=40531&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=40531&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=40531&r=support
Expected behavior: http://bugs.php.net/fix.php?id=40531&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=40531&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=40531&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=40531&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=40531&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=40531&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=40531&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=40531&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=40531&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=40531&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=40531&r=mysqlcfg