|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-11-07 13:48 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 19:00:01 2025 UTC |
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.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.