note 112885 added to function.explode
| From: | crog at gustavus dot edu | Date: | Thu, 01 Aug 2013 19:52:57 +0000 |
| Subject: | note 112885 added to function.explode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-195851@lists.php.net to get a copy of this message | ||
Note that while the documentation states the "If limit is set and positive," passing a
null-value will still result in triggering the "limit is zero" case (as of PHP 5.4.17).
When passing through values (such as using explode to implement an interface method), you'll
need to explicitly check that the limit has been set:
<?php
public function split($string, $delimiter, $limit = null)
{
return isset($limit) ? explode($delimiter, $string, $limit) : explode($delimiter, $string);
}
?>
Failing to check $limit and simply passing through a null-value will return the same value as if
$limit were 0 or 1. To clarify, all of the following will return the same value:
<?php
explode($string, $delimiter, null);
explode($string, $delimiter, 0);
explode($string, $delimiter, 1);
?>
----
Server IP: 69.147.83.199
Probable Submitter: 138.236.71.114
----
Manual Page -- http://php.net/manual/en/function.explode.php
Edit -- https://master.php.net/note/edit/112885
Del: integrated -- https://master.php.net/note/delete/112885/integrated
Del: useless -- https://master.php.net/note/delete/112885/useless
Del: bad code -- https://master.php.net/note/delete/112885/bad+code
Del: spam -- https://master.php.net/note/delete/112885/spam
Del: non-english -- https://master.php.net/note/delete/112885/non-english
Del: in docs -- https://master.php.net/note/delete/112885/in+docs
Del: other reasons-- https://master.php.net/note/delete/112885
Reject -- https://master.php.net/note/reject/112885
Search -- https://master.php.net/manage/user-notes.php