Bug #53252 [NEW]: Invalid type (boolean) returned by substr() when providing an empty string
| From: | cagret at gmail dot com | Date: | Sun, 07 Nov 2010 12:48:33 +0000 |
| Subject: | Bug #53252 [NEW]: Invalid type (boolean) returned by substr() when providing an empty string | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-155818@lists.php.net to get a copy of this message | ||
From:
Operating system: Linux, Windows
PHP version: 5.3.3
Package: Strings related
Bug Type: Bug
Bug description:Invalid type (boolean) returned by substr() when providing an empty string
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 bug report at http://bugs.php.net/bug.php?id=53252&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=53252&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=53252&r=trysnapshot53
Try a snapshot (trunk): http://bugs.php.net/fix.php?id=53252&r=trysnapshottrunk
Fixed in SVN: http://bugs.php.net/fix.php?id=53252&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53252&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=53252&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=53252&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=53252&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=53252&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=53252&r=support
Expected behavior: http://bugs.php.net/fix.php?id=53252&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=53252&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=53252&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=53252&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53252&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=53252&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=53252&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=53252&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=53252&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=53252&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=53252&r=mysqlcfg