Doc #65566 [NEW]: document default value of $length in substr()
From: matteosistisette at gmail dot com
Operating system:
PHP version: Irrelevant
Package: Documentation problem
Bug Type: Documentation Problem
Bug description:document default value of $length in substr()
Description:
------------
---
From manual page:
http://www.php.net/function.substr#refsect1-function.substr-
parameters
---
"""
If length is given and is positive, the string returned will contain at
most
length characters beginning from start (depending on the length of
string).
If length is given and is negative, then that many characters will be
omitted
from the end of string (after the start position has been calculated when a
start is negative). If start denotes the position of this truncation or
beyond,
false will be returned.
If length is given and is 0, FALSE or NULL an empty string will be
returned.
If length is omitted, the substring starting from start until the end of
the
string will be returned.
"""
And what if one needs to specify a value for length and obtain the last
behavior??
That is:
if (/*whatever*/) $length=/*something*/;
else if (/*whatever_else*/) $length=/*something else*/;
else if.....
//...
echo substr ($string, $start, $length);
I guess the solution is to set $length=PHP_INT_MAX.
But then it needs to be better documented by declaring it as the default
value
for $length:
replace this:
string substr ( string $string , int $start [, int $length ] )
with this:
string substr ( string $string , int $start, int $length=PHP_INT_MAX )
Default values for all parameters must ALWAYS be documented, so that one
can
ALWAYS know what value to pass to a function when one has to specify a
value and
one wants the default behavior.
I have found the same problem in various pages of php's docs.
Actually there are cases worst than this (in this case, one can guess it).
--
Edit bug report at https://bugs.php.net/bug.php?id=65566&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=65566&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=65566&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=65566&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=65566&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=65566&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=65566&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=65566&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=65566&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=65566&r=support
Expected behavior: https://bugs.php.net/fix.php?id=65566&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=65566&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=65566&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=65566&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65566&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=65566&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=65566&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=65566&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65566&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=65566&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=65566&r=mysqlcfg
Thread (2 messages)
- matteosistisette at gmail dot com