#28899 [Opn->Asn]: substr and mb_substr work different

From: Date: Thu, 03 Feb 2005 02:25:50 +0000
Subject: #28899 [Opn->Asn]: substr and mb_substr work different
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-73308@lists.php.net to get a copy of this message
ID: 28899 Updated by: sniper@php.net Reported By: mauroi at digbang dot com -Status: Open +Status: Assigned Bug Type: mbstring related Operating System: * PHP Version: 4CVS, 5CVS (2004-12-12) Assigned To: moriyoshi New Comment: Whatever is the "logical" behaviour of the function, it doesn't really matter: We will NOT change the behaviour of substr() at this point. Thus the only place to change is mbstring. Previous Comments: ------------------------------------------------------------------------ [2004-12-20 13:58:20] mauroi at digbang dot com just to mention it... lot of code written with the mb_* function overload relies on substr returning a zero length string... changing substr to work like mb_substr won't break anything (i think) ------------------------------------------------------------------------ [2004-12-20 10:28:55] moriyoshi@php.net The very nature of "substr" is that the function returns the specified part of the string whenever the range is valid and returns an error status if it is out of range. If a null string is a valid string entity, then it should be able to be referred to by index "0" and thus the implementation returns a null string instead of false. Or you would say this isn't really logical? :) ------------------------------------------------------------------------ [2004-12-15 04:19:11] sniper@php.net The correct quote from up-to-date manual: "If string is less than or equal to start characters long, FALSE will be returned." Notice the 'or equal' there? Thus logically mb_substr() is buggy. ------------------------------------------------------------------------ [2004-06-23 22:12:57] moriyoshi@php.net Good catch. Logically it seems substr() is wrong and mb_substr() is correct. ------------------------------------------------------------------------ [2004-06-23 21:21:51] mauroi at digbang dot com 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 this bug report at http://bugs.php.net/?id=28899&edit=1

« previous php.bugs (#73308) next »