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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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: Thu Nov 21 14:01:29 2024 UTC