php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #32785 negative limit doesn't work in explode()
Submitted: 2005-04-20 23:45 UTC Modified: 2005-04-21 20:18 UTC
From: proton@php.net Assigned: nlopess (profile)
Status: Closed Package: Documentation problem
PHP Version: 4.3.10 OS: Debian GNU/Linux
Private report: No CVE-ID: None
 [2005-04-20 23:45 UTC] proton@php.net
Description:
------------
http://www.php.net/explode
Manual gives an example of limit-parameter used in explode().
Example 2 shows negative limit-value example and it seems not working like expected.

Test-code at web: http://mikrolahti.fi/explode.php


Reproduce code:
---------------
<?php
$str = 'one|two|three|four';

// positive limit
print_r(explode('|', $str, 2));

// negative limit
print_r(explode('|', $str, -1));
?>


Expected result:
----------------
Array
(
    [0] => one
    [1] => two|three|four
)
Array
(
    [0] => one
    [1] => two
    [2] => three
)


Actual result:
--------------
Array
(
    [0] => one
    [1] => two|three|four
)
Array
(
    [0] => one
    [1] => two
    [2] => three
    [3] => four
)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-21 00:03 UTC] proton@php.net
It does the same on current PHP-version also.

nandus% uname -a
FreeBSD nandus.mikrolahti.fi 5.4-STABLE FreeBSD 5.4-STABLE #0: Tue Apr 19 23:27:27 EEST 2005     root@nandus.mikrolahti.fi:/usr/obj/usr/src/sys/NANDUS  i386

nandus% cat explode.php
<?php
$str = 'one|two|three|four';

// positive limit
print_r(explode('|', $str, 2));

// negative limit
print_r(explode('|', $str, -1));
?>

nandus% php explode.php
Content-type: text/html
X-Powered-By: PHP/5.0.4

Array
(
    [0] => one
    [1] => two|three|four
)
Array
(
    [0] => one
    [1] => two
    [2] => three
    [3] => four
)
 [2005-04-21 00:43 UTC] sniper@php.net
Reclassified as documentation problem: The examples should have BIG note about the being like that only with PHP 5.1!!!!

 [2005-04-21 00:45 UTC] sniper@php.net
Also: Why the hell do you doc people put something like this in the manual WHEN THERE IS NO SUCH RELEASE ever made with such feature(s)???!!!
 [2005-04-21 00:49 UTC] sniper@php.net
Assigned to Nuno: Thanks for wasting our time.

 [2005-04-21 01:31 UTC] philip@php.net
The documentation does mention this:

If the limit parameter is negative, all components except the last limit are returned. This feature was added in PHP 5.1.0.

Sure the 5.1+ example could have a comment specifying this version requirement but no need to get all crazy! :) When the explode() docs get converted to the new doc style the change will be much clearer as each function now has a CHANGELOG.

We document future versions too, it's the way it is. A more appropriate question is "why not" but anyway it's so people using the manual can handle/know future changes/additions, and that we don't forget to document these changes. See also:

http://php.net/manual/en/about.phpversions.php
 [2005-04-21 12:02 UTC] vrana@php.net
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.

Warning added.

I agree with sniper that documenting not-yet-existing features is work for a work.
 [2005-04-21 20:18 UTC] nlopess@php.net
I don't know whats the problem here.
Thanks Philip for pointing the document that describe our decision to document the new feautures before they are released.
The documentation is not always up-to-date. If we waited for the things to be released.. The documentation would take ages to be updated. What I do is to follow the CVS mailling list and try to document everything new.

Nuno
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Aug 02 01:00:02 2025 UTC