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

From: Date: Sun, 07 Nov 2010 15:23:34 +0000
Subject: Bug #53252 [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-5494@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: Assigned Type: Bug Package: Documentation problem Operating System: Linux, Windows PHP Version: 5.3.3 Assigned To: frozenfire Block user comment: N New Comment: I referred to the documentation example above. Passing in an empty string always returned false. Previous Comments: ------------------------------------------------------------------------ [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 (#5494) next »