Bug #53252 [Opn]: Invalid type (boolean) returned by substr() when providing an empty string
| From: | felipe@php.net | Date: | Sun, 07 Nov 2010 13:08:15 +0000 |
| Subject: | Bug #53252 [Opn]: 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-5490@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: felipe@php.net
Reported by: cagret at gmail dot com
Summary: Invalid type (boolean) returned by substr() when
providing an empty string
Status: Open
Type: Bug
-Package: Strings related
+Package: Documentation problem
Operating System: Linux, Windows
PHP Version: 5.3.3
Block user comment: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[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