thecodingmachine / safe

All PHP functions, rewritten to throw exceptions instead of returning false
MIT License
2.37k stars 153 forks source link

Error in libxml_get_last_error #438

Open temp opened 9 months ago

temp commented 9 months ago
/**
 * Retrieve last error from libxml.
 *
 * @return \LibXMLError Returns a LibXMLError object if there is any error in the
 * buffer, FALSE otherwise.
 * @throws LibxmlException
 *
 */
function libxml_get_last_error(): \LibXMLError
{
    error_clear_last();
    $safeResult = \libxml_get_last_error();
    if ($safeResult === false) {
        throw LibxmlException::createFromPhpError();
    }
    return $safeResult;
}

I guess something got mixed up here. libxml_get_last_error() returns false if no error occurred, but in the safe function this will trigger an Exception.