Bug #53252 [Csd->Asn]: Invalid type (boolean) returned by substr() when providing an empty string

From: Date: Sun, 07 Nov 2010 15:28:33 +0000
Subject: Bug #53252 [Csd->Asn]: Invalid type (boolean) returned by substr() when providing an empty string
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-5496@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=53252&edit=1 ID: 53252 Updated by: philip@php.net Reported by: cagret at gmail dot com Summary: Invalid type (boolean) returned by substr() when providing an empty string -Status: Closed +Status: Assigned Type: Bug Package: Documentation problem Operating System: Linux, Windows PHP Version: 5.3.3 Assigned To: frozenfire Block user comment: N New Comment: Sorry, I'm being unclear this early morning. It's $rest = substr("abcdef", 4, -4) that changed with 5.2.2, the other examples here have always been false. The change probably relates to PHP Bug #40754 In the very least, the substr() documentation needs a changelog entry. Previous Comments: ------------------------------------------------------------------------ [2010-11-07 16:28:15] frozenfire@php.net This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. ------------------------------------------------------------------------ [2010-11-07 16:23:33] philip@php.net I referred to the documentation example above. Passing in an empty string always returned false. ------------------------------------------------------------------------ [2010-11-07 16:21:22] philip@php.net 5.2.2 broke this (or fixed) but it's a BC issue. Before this time, it returned "". ------------------------------------------------------------------------ [2010-11-07 14:08:15] felipe@php.net The example in the documentation must be fixed. And about your example, we have an example in the documentation that is just like your case: var_dump(substr('a', 1)); // bool(false) That is the expected behavior. ------------------------------------------------------------------------ [2010-11-07 13:48:33] cagret at gmail dot com Description: ------------ substr() returns boolean false when providing an empty string as first argument, but it should return an empty string "". Example: <?php $s = substr('', 0, 1); echo gettype($s); ?> Output: boolean (false) There is an *error in php documentation*: http://pl.php.net/manual/en/function.substr.php See the example for the third argument "Length": >> $rest = substr("abcdef", 4, -4); // returns "" That is not true, $rest contains FALSE and not "". Cheers, Cezary Tomczak ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=53252&edit=1

« previous php.doc.bugs (#5496) next »