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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jordi dot salvat at localbilinglimited dot com
New email:
PHP Version: OS:

 

 [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-2021 The PHP Group
All rights reserved.
Last updated: Tue Dec 07 19:03:40 2021 UTC