Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplexml_load_string does not work out of the box #267

Open
nreynis opened this issue Jan 21, 2021 · 0 comments
Open

simplexml_load_string does not work out of the box #267

nreynis opened this issue Jan 21, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@nreynis
Copy link

nreynis commented Jan 21, 2021

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);
        }
@shish shish added the enhancement New feature or request label Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants