#48035 [NEW]: explode() returns empty array if delimiter not found and limit is negative
From: Bjorn dot Wiberg at its dot uu dot se
Operating system: Debian 5.0.1, IBM AIX 5.3
PHP version: 5.2.9
PHP Bug Type: Unknown/Other Function
Bug description: explode() returns empty array if delimiter not found and limit is negative
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 bug report at http://bugs.php.net/?id=48035&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=48035&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=48035&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=48035&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=48035&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=48035&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=48035&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=48035&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=48035&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=48035&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=48035&r=support
Expected behavior: http://bugs.php.net/fix.php?id=48035&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=48035&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=48035&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=48035&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=48035&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=48035&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=48035&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=48035&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=48035&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=48035&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=48035&r=mysqlcfg
Thread (4 messages)
- Bjorn dot Wiberg at its dot uu dot se