#28899 [NEW]: substr and mb_substr work different

From: Date: Wed, 23 Jun 2004 19:21:52 +0000
Subject: #28899 [NEW]: substr and mb_substr work different
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-61262@lists.php.net to get a copy of this message
From:             mauroi at digbang dot com
Operating system: All
PHP version:      Irrelevant
PHP Bug Type:     Strings related
Bug description:  substr and mb_substr work different

Description:
------------
if I make the following call I get FALSE.

var_dump(substr('', 0));

The documentation says "If string is less than start characters long,
FALSE will be returned".
That can be very ambiguous because start is 0 and the length of the
string is 0 (not less).
Another problem: mb_substr does not work like this. If you overload the
functions and make the same call as above it will return an empty
string.

Thanks in advance.


Reproduce code:
---------------
var_dump(substr('', 0));
var_dump(mb_substr('', 0));


Expected result:
----------------
''
''

Or 

FALSE
FALSE

Actual result:
--------------
FALSE
''

-- 
Edit bug report at http://bugs.php.net/?id=28899&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=28899&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=28899&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=28899&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=28899&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=28899&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=28899&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=28899&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=28899&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=28899&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=28899&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=28899&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=28899&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28899&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=28899&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=28899&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=28899&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=28899&r=float


Thread (9 messages)

« previous php.bugs (#61262) next »