I've tried looking at a lot of solutions and still can't seem to find a fix for my issue. I keep getting the following error:
Parameter #2 $string of function explode expects string, SimpleXMLElement|null given.
I've never had this issue before and it's only started appearing after updating Statamic to the latest version. This is my code within the GenerateFavicons.php:
private function createThumbnail(
string $import,
string $export,
int $width,
int $height,
string $background,
?int $border
): void {
$svg = file_get_contents($import);
if (!$svg) {
return;
}
$svgObj = simplexml_load_string($svg);
if (!$svgObj) {
return;
}
$viewBox = explode(' ', $svgObj['viewBox']);
$viewBoxWidth = intval($viewBox[2]);
$viewBoxHeight = intval($viewBox[3]);
The error is showing for the following line of code:
$viewBox = explode(' ', $svgObj['viewBox']);
From what I've seen, a lot of people have been saying you shouldn't explode an array. I'm not quite sure where to go from here.
Thanks in advance.
explode an array? It's already broken into pieces. Also, your error is saying that$svgObj['viewBox']is not a string. Did tryvar_dump($svgObj['viewBox'])to see what$svgObj['viewBox']is?$svgObj['something']is itself aSimpleXMLElement(or could benull) which is what the warning is about. The code itself will probably work because of type juggling but it's better to explicitly cast it using e.g.explode(' ', strval($svgObj['viewBox'])). Seeing how the value could be null it's probably good to check that as well