P粉4492810682023-08-16 17:52:28
The definition of function implode
is very roughly equivalent to the following code (this is just an example, not tested):
function not_really_implode($glue, $pieces) { $result = ''; $first = true; foreach ( $pieces as $piece ) { if ( ! $first ) { $result .= $glue; } $pieceAsString = (string)$piece; $result .= $pieceAsString; $first = false; } return $result; }The key point is this line of code:
$pieceAsString = (string)$piece; - In order to combine the elements of the array,
implode must
each element one by oneConvert to string.
$pieces looked like this:
$pieces = [ 'one', ['two-a', 'two-b'], 'three', ];At some point in our loop we will have
$piece = ['two-a', 'two-b'] and try to convert it to a string - oops!
your $_REQUEST array, there are other arrays. Several ways this could happen:
can be written directly. For example, someone could write
$_REQUEST['example'] = ['a', 'b'];
, and
$_REQUEST would be automatically populated as
['a', 'b '].
Never trust user input! It is very dangerous to make any assumptions about the content in
$_REQUEST, because the input is under the control of the user, and the user may not be yours friend.