Edit report at https://bugs.php.net/bug.php?id=42129&edit=1

 ID:                 42129
 Comment by:         alastair at propcom dot co dot uk
 Reported by:        david dot nqd at gmail dot com
 Summary:            restrict explode's function return type
 Status:             Open
 Type:               Feature/Change Request
 Package:            Feature/Change Request
 Operating System:   Irrelevant
 PHP Version:        5.2.3
 Block user comment: N
 Private report:     N

 New Comment:

This affects me too.

I don't want this to be my string-split paradigm:

if ($delimiter === '') return str_split($str);
else return explode($delimiter, $str);

That's just stupid. Splitting on the empty string is a completely logical and 
well-defined operation.


Previous Comments:
------------------------------------------------------------------------
[2007-07-27 22:01:06] david dot nqd at gmail dot com

Description:
------------
This is not a bug report like #38337.

Shouldn't the return type of explode be restricted to an array given valid 
inputs (strings)?
This would mean that if an empty string was passed as the delimiter, the return 
would be an array containing individual characters.

I doubt this would break any existing code unless people used explode to check 
that the delimiter === ''

Reproduce code:
---------------
<?php
$x = explode('', 'abc');
?>

Expected result:
----------------
$x = array('a','b','c')

Actual result:
--------------
$x = false


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=42129&edit=1

Reply via email to