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