php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47546 Default value for limit parameter in explode is 0, not -1
Submitted: 2009-03-02 17:25 UTC Modified: 2009-04-01 17:18 UTC
From: jordi dot salvat at localbilinglimited dot com Assigned: kalle (profile)
Status: Not a bug Package: Strings related
PHP Version: 5.2.9 OS: Irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
46 - 23 = ?
Subscribe to this entry?

 
 [2009-03-02 17:25 UTC] jordi dot salvat at localbilinglimited dot com
Description:
------------
http://es.php.net/explode declares that the default value for the 3rd parameter of the explode function is -1.

The function, however, behaves differently when -1 is passed explicitly.


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

print_r(explode('|', $str));
print_r(explode('|', $str, -1));
?>
__END__


Expected result:
----------------
From the documentation, I would expect to see the same result twice.

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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-03 11:51 UTC] kalle@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.

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.

Fixed in PHP 5.2.10
 [2009-04-01 17:18 UTC] mattwil@php.net
Change reverted, as the behavior was correct. It's the documentation that's wrong. See Bug #47560 and Bug #47727.

The default value for limit (3rd parameter) is just "unlimited," or the length of the input string, or PHP_INT_MAX, etc.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 08:01:29 2024 UTC