The PHP docs for join() and explode() say that the $glue and $delimiter must be strings. I tried this and it doesn’t throw any errors:
$glue = -8.5;
$delimiter = 0;
echo join( $glue, explode($delimiter, '1_0_1') ); // '1_-8.5_1'
So if I’m checking a $var that could be used as $glue or $delimiter, then is it safe to use is_string($var) || is_numeric($var)
as a condition OR are there times where that could be true but there’d be an error from the join() or explode()?
You can just do type casting like this:
At any rate, it appears they were being converted anyway.
Still, it would be good to use
is_string()andis_numeric()to avoid a catchable fatal error if, say, an object was passed.Edit
Per ryanve’s suggestion, you could do this too: