note 112885 deleted from function.explode by salathe

From: Date: Mon, 21 Sep 2020 14:48:57 +0000
Subject: note 112885 deleted from function.explode by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-215324@lists.php.net to get a copy of this message
Note Submitter: crog at gustavus dot edu ---- 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); ?>

« previous php.notes (#215324) next »