Req #42129 [Opn]: restrict explode's function return type

From: Date: Wed, 31 Dec 2014 16:24:44 +0000
Subject: Req #42129 [Opn]: restrict explode's function return type
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-189564@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=42129&edit=1 ID: 42129 Updated by: nikic@php.net 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 +Package: *General Issues Operating System: Irrelevant PHP Version: 5.2.3 Block user comment: N Private report: N New Comment: Note that if explode('', 'abc') were implemented the correct result would actually be array('', 'a', 'b', 'c', ''), which would be unexpected to many people. To avoid confusion PHP does not allow this usage. Previous Comments: ------------------------------------------------------------------------ [2012-07-19 14:52:43] alastair at propcom dot co dot uk 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. ------------------------------------------------------------------------ [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

« previous php.bugs (#189564) next »