Doc #62613 [Opn]: 'explode' quirk
| From: | matthew at binaryrefined dot net | Date: | Thu, 19 Jul 2012 20:49:25 +0000 |
| Subject: | Doc #62613 [Opn]: 'explode' quirk | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-8584@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62613&edit=1
ID: 62613
User updated by: matthew at binaryrefined dot net
Reported by: matthew at binaryrefined dot net
Summary: 'explode' quirk
Status: Open
Type: Documentation Problem
Package: Arrays related
Operating System: Win XP, SP3
PHP Version: 5.4.4
Block user comment: N
Private report: N
New Comment:
To block against this, I've had to do a boolean check against the variable before applying
explode to ensure an empty source
string will produce an empty array:
if ($x)
{
$x = explode('|', $x);
}
else
{ ... } // $x is empty, and if passed to explode, results in an array with a single, empty
element.
I've been developing with PHP for ~10 years and I cannot ever remember having to do this with
explode. The more I think about
it, the more I believe this may be a bug?
Thanks for the time.
Previous Comments:
------------------------------------------------------------------------
[2012-07-19 20:24:18] matthew at binaryrefined dot net
Description:
------------
When providing an empty source string to explode, it returns an array with a
single, empty element. Expected behavior was an empty array.
Test script:
---------------
<?php
$x = explode('|', ''); // '' would be a variable, and not
intentionally empty.
print_r($x);
?>
Expected result:
----------------
Array ()
Actual result:
--------------
Array ( [0] => )
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62613&edit=1