note 90369 modified in function.substr by danbrown
| From: | danbrown@php.net | Date: | Sat, 18 Apr 2009 12:56:01 +0000 |
| Subject: | note 90369 modified in function.substr by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153466@lists.php.net to get a copy of this message | ||
You might expect substr('123456', 6) to return an empty string. Instead it returns boolean
FALSE.
This behavior should be mentioned in the Return Values section of the manual. Instead it is only
mentioned in the Parameters section.
If you need an empty string instead of a boolean FALSE you should typecast the result to a string.
<?php
$a = substr('123456', 6); // equivalent to $a = FALSE
$a = (string) substr('123456', 6); // equivalent to $a = '';
?>
--was--
You might expect substr('123456', 6) to return an empty string. Instead it returns boolean
FALSE.
This behavior should be mentioned in the Return Values section of the manual. Instead it is only
mentioned in the Parameters section.
If you need an empty string instead of a boolean FALSE you should typecast the result to a string.
$a = substr('123456', 6); // equivalent to $a = FALSE
$a = (string) substr('123456', 6); // equivalent to $a = '';
http://php.net/manual/en/function.substr.php