Closed
Description
Problem description
- Library version or last commit you have
1c1b4076
- PHP version you use
8.0.0
- Detailed problem description
phpGPX\Parsers\PersonParser.php:48;"Invalid argument supplied for foreach()"
If you think that problem is connected with your file content, please attach it to the issue.
Code snippet you use
$gpx = new phpGPX();
$gpx_file = $gpx->load($filein);
....
$p = new Person();
$p->name = "blabla";
$gpx_file->metadata->author = $p;
.....
$out = $gpx_file->toXML()->saveXML();
Expected behaviour
script continue even if $person->links is null
Possible solution
diff --git "a/src/phpGPX/Parsers/PersonParser.php" "b/src/phpGPX/Parsers/PersonParser.php"
index 8795bc8..227b864 100644
--- "a/src/phpGPX/Parsers/PersonParser.php"
+++ "b/src/phpGPX/Parsers/PersonParser.php"
@@ -45,9 +45,11 @@ abstract class PersonParser
$node->appendChild($child);
}
- foreach ($person->links as $link) {
- $child = LinkParser::toXML($link, $document);
- $node->appendChild($child);
+ if(!is_null($person->links)){
+ foreach ($person->links as $link) {
+ $child = LinkParser::toXML($link, $document);
+ $node->appendChild($child);
+ }
}
return $node;
and may the !is_null() test must be done somewhere else
Something interesting or funny
#confinedshortreading https://craphound.com/overclocked/Cory_Doctorow_-_Overclocked_-_When_Sysadmins_Ruled_the_Earth.html
Checklist
Put x
into brackets if true.
[X] PHP version I use
[X] Package version I use