#48035 [Opn->Tbd]: explode() returns empty array if delimiter not found and limit is negative
| From: | iliaa@php.net | Date: | Tue, 21 Apr 2009 12:21:04 +0000 |
| Subject: | #48035 [Opn->Tbd]: explode() returns empty array if delimiter not found and limit is negative | ||
| References: | 1 | Groups: | php.bugs php.doc.bugs |
| Request: | Send a blank email to php-bugs+get-136084@lists.php.net to get a copy of this message | ||
ID: 48035
Updated by: iliaa@php.net
Reported By: Bjorn dot Wiberg at its dot uu dot se
-Status: Open
+Status: To be documented
Bug Type: Strings related
Operating System: Debian 5.0.1, IBM AIX 5.3
PHP Version: 5.2.9
New Comment:
.
Previous Comments:
------------------------------------------------------------------------
[2009-04-21 11:19:00] Bjorn dot Wiberg at its dot uu dot se
Description:
------------
It appears that explode() returns an empty array (instead of an array
with string in it) if limit is negative and delimiter contains a value
that is not contained in string.
The documentation of explode()
(http://www.php.net/manual/en/function.explode.php, section "Return
Values") however states that "If delimiter contains a value that is not
contained in string, then explode() will return an array containing
string", which then does not hold for negative limits.
Reproduce code:
---------------
<?php
print_r(explode('_', 'test', -1));
print_r(explode('_', 'test_underscore', -1));
print_r(explode('_', 'test'));
print_r(explode('_', 'test_underscore'));
?>
Expected result:
----------------
Array
(
[0] => test
)
Array
(
[0] => test
)
Array
(
[0] => test
)
Array
(
[0] => test
[1] => underscore
)
Actual result:
--------------
bwiberg@musica-lp02:~$ php -n -f test.php
Array
(
)
Array
(
[0] => test
)
Array
(
[0] => test
)
Array
(
[0] => test
[1] => underscore
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48035&edit=1