Open
Description
simplexml_load_string
will not return false, but will emits errors unless you are setting libxml_use_internal_errors(true);
before.
I am not sure this is necessarly something you want to handle. 🤔
To me that kind of looks like an encapsulation issue: I expect the library to get care of those details and provide me an exception.
Instead I've got to do all that by myself:
try {
libxml_use_internal_errors(true);
$result = \Safe\simplexml_load_string($data, $class_name, $options, $namespace_or_prefix, $is_prefix);
libxml_clear_errors();
return $result;
} catch (SimplexmlException $e) {
$messages = [];
foreach (libxml_get_errors() as $error) {
$messages[] = $error->message;
}
libxml_clear_errors();
$message = 'Impossible to process the provided XML: '.join(', ', $messages);
throw new SimplexmlException($message, $e);
}