#32865 [Opn->Bgs]: explode do not works with $limit = null
| From: | derick@php.net | Date: | Thu, 28 Apr 2005 11:08:22 +0000 |
| Subject: | #32865 [Opn->Bgs]: explode do not works with $limit = null | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-78361@lists.php.net to get a copy of this message | ||
ID: 32865
Updated by: derick@php.net
Reported By: dan at yes dot lt
-Status: Open
+Status: Bogus
Bug Type: Strings related
Operating System: WinXP
PHP Version: 5.0.4
New Comment:
No, it's how the language works.
Previous Comments:
------------------------------------------------------------------------
[2005-04-28 13:06:47] dan at yes dot lt
now I have to write..
if ($lim === null) {
$parts = explode(',', $str);
} else {
$parts = explode(',', $str, $lim);
}
..instead of..
$parts = explode(',', $str, $lim);
Isn't it some sort of crap ?..
------------------------------------------------------------------------
[2005-04-28 12:09:12] dan at yes dot lt
So what should I give to $limit to explode unlimited ???... As I know -
in PHP no parameter means some default value - what default value is
defined to default $limit ?..
------------------------------------------------------------------------
[2005-04-28 11:43:01] sniper@php.net
Yes, null == 0. (PHP is still loose typed language..)
------------------------------------------------------------------------
[2005-04-28 11:19:04] dan at yes dot lt
Description:
------------
explode() do not explodes string if $limit argument is null, but
explodes if no $limit argument given.
Reproduce code:
---------------
print_r(explode(',', 'a,b,c'));
print_r(explode(',', 'a,b,c', null));
Expected result:
----------------
Array
(
[0] => a
[1] => b
[2] => c
)
Array
(
[0] => a
[1] => b
[2] => c
)
Actual result:
--------------
Array
(
[0] => a
[1] => b
[2] => c
)
Array
(
[0] => a,b,c
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=32865&edit=1